Pergunta

I am accessing the PDF files available in my PHP server using my iPhone with the help of passing file url to CGPDFDocumentCreateWithURL. My question whenever i access the files it will downloaded to my iphone documents directory or not?

Because if my application in active for some time i am getting the error CFURLCreateDataAndPropertiesFromResource with error code -14. After getting this error my application is not crashed but it is not functioning properly.

I am not able to understand the internal process? Please help me in this issue?

Foi útil?

Solução

I think you're misunderstanding what CGPDFDocumentCreateWithURL does. It does not download a PDF document to the filesystem. It creates a PDF in memory based off the URL provided. It doesn't save anything to the filesystem.

I would strongly recommend you use a networking class (NSURLConnection, ASI, etc) to download the PDF first and then open it. This will enable you to provide better feedback, and support more advanced download features such as resuming partial downloads, providing progress, and better thread management.

Outras dicas

To save the PDF

NSString *urlString = @"http://www.web.com/url/for/document.pdf";

NSURL *url = [NSURL URLWithString:urlString];

NSData *data = [NSData dataWithContentsOfURL:url];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:@"myLocalFileName.pdf"];

[data writeToFile:pdfPath atomically:YES];

then load that saved file into a web view:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:@"myLocalFileName.pdf"];

NSURL *url = [NSURL fileURLWithPath: pdfPath];

NSURLRequest *request = [NSURLRequest requestWithURL:url];

[[self mainWebView] loadRequest:request];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top