【问题标题】:ios development: Saved file does not show up in itunesios开发:保存的文件不显示在iTunes中
【发布时间】:2011-05-05 17:41:39
【问题描述】:

当我使用 URL 将 PDF 保存到文件时,保存的 pdf 不会显示在 Itunes/我的 iPad 名称/应用程序/MyApp 的文档窗口中。实际上,我什至在“文件共享”部分下都看不到我的应用程序。 “dropbox”或“pages”之类的应用是如何做到的?

使用的代码
//我想要的pdf的url
NSURL *pdfURL = [NSURL URLWithString:@"http://manuals.info.apple.com/en/iphone_user_guide.pdf"];

// 获取我们文档目录的路径
NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

//这应该是我们的文档目录
NSString *saveDirectory = [documentPath objectAtIndex:0];
NSString *saveDirectory2 = [[saveDirectory stringByAppendingPathComponent:@"myfile.pdf"] retain];

//将我的 PDF 转换为 NSData,也许我无法从 PDF 转换?
NSData *dataToWrite = [NSData dataWithContentsOfURL:pdfURL];

//将转换后的pdf写入内存路径
BOOL status = [dataToWrite writeToFile:saveDirectory2 atomically:YES];

【问题讨论】:

    标签: iphone file ios save


    【解决方案1】:

    您是否已按照此处的说明将 UIFileSharingEnabled 键添加到应用的 Info.plist 文件并将其值设置为 YES?:

    http://developer.apple.com/library/ios/#documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html%23//apple_ref/doc/uid/TP40009252-SW20

    没有它,iTunes 将无法查看您应用的 Documents 目录中的内容。

    【讨论】:

      【解决方案2】:

      在新的 Xcode 中,您可以在 UI 中执行此操作:

      1. Select your project in top left
      2. Select target in next column
      3. Click on Info tab
      4. In Custom iOS Target Properties, hover mouse over any row and click +
      5. In popup, select "Application supports iTunes file sharing", then set Value to YES on right
      6. Click Validate Settings at bottom to make sure all is good
      

      【讨论】:

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