【发布时间】:2015-11-30 19:39:49
【问题描述】:
我想将数据从我的 iPhone 导入我的应用程序。到目前为止,我已经成功导入了照片库和音乐,但我还想在我的 iOS 应用程序中导入 pdf 和其他文档?我怎样才能做到这一点?
【问题讨论】:
标签: ios iphone nsdocumentdirectory
我想将数据从我的 iPhone 导入我的应用程序。到目前为止,我已经成功导入了照片库和音乐,但我还想在我的 iOS 应用程序中导入 pdf 和其他文档?我怎样才能做到这一点?
【问题讨论】:
标签: ios iphone nsdocumentdirectory
您必须将您的应用程序与您要打开的 PDF 类型相关联。您可以通过向 Info.plist 添加一些参数来做到这一点。
有一个很好回答的帖子解释了这一点:
How do I associate file types with an iPhone application?
您还应该考虑阅读 Apple 的 documentation 和我写的博客 post。
【讨论】:
你不能在 iOS 8 中做到这一点(虽然我还没有检查 9)。您甚至无法在 iBooks 的共享菜单中加入您的应用(添加相应的 URL 方案)。
【讨论】:
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
NSFileManager *mgr = [[NSFileManager alloc] init];
NSArray *allFiles = [mgr contentsOfDirectoryAtPath:bundlePath error:NULL];
for (NSString *fileName in allFiles)
{
if ([[fileName pathExtension] isEqualToString:@"pdf"])
{
NSString *fullFilePath = [bundlePath stringByAppendingPathComponent:fileName];
// fullFilePath now contains the path to your pdf file
// DoSomethingWithFile(fullFilePath);
NSLog(@"file: %@",fullFilePath);
}
}
NSURL *url = [[NSBundle mainBundle] URLForResource:@"" withExtension: @"pdf"];
NSLog(@"File: %@",url);
【讨论】: