首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >手术无法完成。(可可误差260.)

手术无法完成。(可可误差260.)
EN

Stack Overflow用户
提问于 2013-05-06 08:32:02
回答 2查看 16.4K关注 0票数 2

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

代码语言:javascript
复制
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];

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

谢谢你的帮忙

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-05-06 08:57:45

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

问题是您的路径仍然包含编码空格(%20),因为它是基于URL的。您可以简单地这样做:

代码语言:javascript
复制
NSData *pdfData = [NSData dataWithContentsOfFile:[document.fileURL path]];
票数 8
EN

Stack Overflow用户

发布于 2013-05-06 08:35:40

尝试使用NSBundle

代码语言:javascript
复制
NSString *newPath = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"pdf"]

编辑:

以下是一个可以使用bundleWithPath方法的示例:

代码语言:javascript
复制
NSString *documentsDir= [NSString stringWithFormat:@"%@/Documents", NSHomeDirectory()];

NSString *newPath= [[NSBundle bundleWithPath:documentsDir] bundlePath];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16394876

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档