【问题标题】:Loading PDF file from Resource directory in iPhone crashes从 iPhone 中的资源目录加载 PDF 文件崩溃
【发布时间】:2011-04-30 00:56:26
【问题描述】:
NSURL *pdfURL = [[NSBundle mainBundle] URLForResource:@"sampleLayout.pdf" withExtension:nil];

上面这行警告NSBundle 可能无法响应-URLForResource:withExtension: 并且应用程序在从该 URL 路径加载 PDF 文件时崩溃。

【问题讨论】:

  • 如果您收到警告和崩溃,则此方法不存在。您使用的是早期的 SDK 吗?这个方法是在 iOS 4.0 中添加的,在此之前不会存在(所以如果你正在为 3.2 或 3.1 或其他东西构建......)
  • 是的,Jason 我正在为 iPad 做这个,所以它在 3.2 上运行,抱歉我之前没有提到

标签: iphone nsurl nsbundle


【解决方案1】:

你为什么不试试这样..?

NSString *urlPath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:urlPath];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webViewOutlet loadRequest:urlRequest];

【讨论】:

  • 感谢 Aji 我以前试过这个,它也崩溃了,没有任何警告。无论如何,这对我的 Web 服务请求很有用,.. 现在我在绘图上下文中绘制这个 pdf 文件
【解决方案2】:

NSURL *pdfPath = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"]];

我从上面的这条线开始工作,我认为这是 iphone 4.0 os 的 ipad 3.2 的替代品

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-31
    • 2016-02-18
    • 1970-01-01
    • 2013-12-19
    相关资源
    最近更新 更多