该操作无法完成.(可可错误260.)

2 iphone cocoa-touch objective-c ipad ios

我是IOS开发的新手,我正在开发一个pdf应用程序,我需要在NSData变量上存储PDF文件,我有PDF路径,但是当我尝试将此pdf放在NSData上时,我收到此消息错误变量使用dataWithContentsOfFile她是我的简单代码:

NSError *error;
NSString *PdfPath = [NSString stringWithFormat:(@"%@"),document.fileURL ];
NSString *newPath = [PdfPath stringByReplacingOccurrencesOfString:@"file://localhost" withString:@""];
NSLog(@"OriginalPdfPath => %@", newPath);
NSData *pdfData = [NSData dataWithContentsOfFile:newPath options:NSDataReadingUncached error:&error];
Run Code Online (Sandbox Code Playgroud)

注意:pdf路径采用以下格式: /Users/bluesettle/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/BBEF320E-7E2A-49DA-9FCF-9CFB01CC0402/ContractApp.app/Pro.iOS.Table.Views .PDF

谢谢你的帮助

And*_*Ley 8

Cocoa错误260是NSFileReadNoSuchFileError(如中所列FoundationErrors.h),意味着在您指定的路径中找不到该文件.

问题是您的路径仍然包含编码空格(%20),因为您将其基于URL.你可以这样做:

NSData *pdfData = [NSData dataWithContentsOfFile:[document.fileURL path]];
Run Code Online (Sandbox Code Playgroud)