【发布时间】:2013-04-09 15:22:13
【问题描述】:
我的应用程序会下载一个 pdf,然后按下按钮将其显示在新视图中。
我得到错误:
-[NSURL initFileURLWithPath:]: nil string parameter'
经过一些故障排除后,我将问题固定在此代码 sn-p 中的某个位置。指向的路径位于下载的 pdf 所在的 /Documents 文件夹中。因此该文档不在主包中。
NSString *path = [[NSBundle mainBundle] pathForResource:PDFpathwithextension ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
这里是下载代码:
//Start an NSURL connection to download from the remotepath
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:remotepathURL];
//Store the Data locally as PDF File
NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];
NSString *filePath = [resourceDocPath stringByAppendingPathComponent:[newdata.ThirdPickerName stringByAppendingFormat:@".pdf"]];
pdfData writeToFile:filePath atomically:YES];
【问题讨论】:
-
从技术上讲,您在这里看到了一个异常,这会导致崩溃