我的應用下載PDF然後在按鈕按下時將其顯示在新視圖中。當試圖在新視圖中打開下載的pdf時崩潰
我得到的錯誤:
-[NSURL initFileURLWithPath:]: nil string parameter'
一些故障排除我壓住了問題的地方在此代碼段後。指向的路徑位於下載的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];
從技術上講,你在這裏看到一個異常,這導致崩潰 – 2013-04-09 15:54:32