【问题标题】:iOS How to open pdf, not from NSBundleiOS如何打开pdf,而不是从NSBundle
【发布时间】:2013-03-30 00:50:00
【问题描述】:

我有一个需要注释 pdf 的应用程序。我一直在使用来自how to edit a PDF in objective-c? 的代码,它很棒,除了文件位置部分。我正在使用

获取 pdf
NSString *newFilePath = [[NSBundle mainBundle] pathForResource:@"Untitled_4" ofType:@"pdf"];

这在模拟器中有效,但在我的测试 iPad 上无效。

我收到了这个错误:

CGDataConsumerCreateWithFilename: failed to open 'long boring file path' for writing: Operation not permitted.

我也玩过

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *newFilePath = [documentsDirectory stringByAppendingPathComponent:@"Untitled_4.pdf"];

我现在明白“您不能写入应用程序包”。谢谢The operation couldn’t be completed. Operation not permitted

当我稍后尝试打开新的带注释的 pdf 时,它无法正确打开。

任何帮助将不胜感激。你们摇滚!

希望这将帮助所有在 iOS 中需要 pdf 注释帮助的其他人。

【问题讨论】:

  • 你NSLog变量newFilePath了吗?
  • 是的,我做到了。它返回了我在上面称为“长无聊文件路径”的相同长字符串
  • 具体来说是“/var/mobile/Applications/EFEF65E1-5D45-4720-A2D8-3B3AFE04D2E5/TeacherTableView4.app/Untitled_4.pdf”

标签: ios pdf annotations directory bundle


【解决方案1】:

回答我自己的问题。

我最终使用了

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *newFilePath = [documentsDirectory stringByAppendingPathComponent:@"Untitled_4.pdf"];

然后画出一切。

问题不存在,它是稍后获取完成的 pdf 以显示它。我以后需要使用相同的代码。

感谢您的帮助。

希望以后发现这个问题的困惑的人也能解决他们的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-02
    相关资源
    最近更新 更多