【问题标题】:How to get device's pdfs and other files in iOS app?如何在 iOS 应用程序中获取设备的 pdf 和其他文件?
【发布时间】:2015-11-30 19:39:49
【问题描述】:

我想将数据从我的 iPhone 导入我的应用程序。到目前为止,我已经成功导入了照片库和音乐,但我还想在我的 iOS 应用程序中导入 pdf 和其他文档?我怎样才能做到这一点?

【问题讨论】:

    标签: ios iphone nsdocumentdirectory


    【解决方案1】:

    您必须将您的应用程序与您要打开的 PDF 类型相关联。您可以通过向 Info.plist 添加一些参数来做到这一点。

    有一个很好回答的帖子解释了这一点:

    How do I associate file types with an iPhone application?

    您还应该考虑阅读 Apple 的 documentation 和我写的博客 post

    【讨论】:

      【解决方案2】:

      你不能在 iOS 8 中做到这一点(虽然我还没有检查 9)。您甚至无法在 iBooks 的共享菜单中加入您的应用(添加相应的 URL 方案)。

      【讨论】:

        【解决方案3】:
            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);
        

        【讨论】:

        • 先生,我需要我的设备的 PDF 和文档而不是我的项目目录,就像如果我想在我的应用程序中导入任何照片,它会打开 photoLibrary 并从那里选择项目。如果 pdf 正在 ibook 上运行,我通过我的音乐同步我希望在我的应用程序中导入
        猜你喜欢
        • 2010-12-03
        • 2012-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多