开发者

CGPDFDocumentCreateWithURL will download the file in to documents directory or not

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 fo开发者_运维问答r 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?


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.


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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜