我的应用程序下载了一个 pdf,然后按下按钮将其显示在一个新视图中。
我得到错误:
-[NSURL initFileURLWithPath:]: nil string parameter'
经过一些故障排除后,我将问题固定在此代码片段中的某个位置。指向的路径/Documents
位于下载的 pdf 所在的文件夹中。因此,该文档不在主捆绑包中。
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];