iOS如何打开pdf,而不是从NSBundle

iOS如何打开pdf,而不是从NSBundle,ios,pdf,annotations,directory,bundle,Ios,Pdf,Annotations,Directory,Bundle,我有一个应用程序,我需要注释一个pdf。我一直在使用来自的代码,除了文件位置部分之外,它非常棒。我是通过使用 NSString *newFilePath = [[NSBundle mainBundle] pathForResource:@"Untitled_4" ofType:@"pdf"]; 这在模拟器中工作,但在我的测试iPad上不起作用 我得到了这个错误: CGDataConsumerCreateWithFilename: failed to open 'long boring file

我有一个应用程序,我需要注释一个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"];
我现在明白了“您不允许写入应用程序包。”谢谢

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

任何帮助都将不胜感激。你们太棒了


希望这能帮助其他需要iOS中pdf注释帮助的人。

回答我自己的问题

我最终使用了

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *newFilePath = [documentsDirectory stringByAppendingPathComponent:@"Untitled_4.pdf"];
然后画所有的东西

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

谢谢你的帮助


希望以后发现此错误的人也能解决问题。

是否记录了变量newFilePath?是的。它返回了我上面称为“长文件路径”的相同长字符串,具体来说,它是“/var/mobile/Applications/efefef65e1-5D45-4720-A2D8-3B3AFE04D2E5/TeacherTableView4.app/Untitled_4.pdf”