私のアプリは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];