【问题标题】:How do I enable the iOS Files app to copy files into my app?如何启用 iOS 文件应用程序以将文件复制到我的应用程序中?
【发布时间】:2020-09-30 18:00:16
【问题描述】:

我有一个使用 iCloud Drive 存储纯文本文件的应用程序,它运行良好——我可以将文件保存到 iCloud Drive,我的应用程序文件夹正确显示,我创建的文件在那里,可以复制出来、共享等……

我现在想让用户使用“文件”应用将他们自己的文本文件复制到我的应用文件夹中,但在“文件”应用中,只要选择了我的应用文件夹,移动按钮就会被禁用。

我在 info.plist 中添加了一个 CFBundleTypes 条目:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array/>
        <key>CFBundleTypeName</key>
        <string>Text</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.plain-text</string>
        </array>
    </dict>
</array>

并启用文件共享和就地打开:

<key>UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>

但这并没有什么不同。我也尝试过添加这样的导入声明:

<key>UTImportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.text</string>
        </array>
        <key>UTTypeDescription</key>
        <string>Text file</string>
        <key>UTTypeIconFiles</key>
        <array/>
        <key>UTTypeIdentifier</key>
        <string>public.text</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>txt</string>
            <key>public.mime-type</key>
            <string>text/plain</string>
        </dict>
    </dict>
</array>

但这也无济于事,即使在重新启动 iPhone 之后也是如此。只要选择了我的应用程序的文件夹,文件“应用程序移动”按钮会灰色。

我怀疑我可能走错了路,这确实是某种权限问题,但我在 Apple 的文档中没有看到任何关于权限的内容,只是关于文件类型的内容。在我的 Mac 上,该文件夹显示正常,我可以毫无问题地将文件拖入其中,并且我的应用程序可以正常识别它们。只有 iOS 文件应用不会保存到我的文件夹中。

是否有人了解如何在“文件”应用中将文本文件复制到我的应用文件夹中,或者什么可能导致“文件”应用拒绝在其中移动文件?

【问题讨论】:

  • 你记得设置UIFileSharingEnabledLSSupportsOpeningDocumentsInPlace吗?
  • 我确实设置了那些@matt - 我会更新我的问题

标签: ios icloud-drive


【解决方案1】:

我写信给 Apple 开发支持并收到了非常有用的回复。简短的回答是增加应用程序的内部版本号,以便让 iCloud 注意到更改,重要的是内部版本号高于任何以前的内部版本号(换句话说,不要只是将其更改为另一个值,更改它到更高的值)。

【讨论】:

    猜你喜欢
    • 2011-10-25
    • 2017-11-07
    • 2011-10-10
    • 1970-01-01
    • 1970-01-01
    • 2013-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多