Search code examples
iosicloud-drive

How do I enable the iOS Files app to copy files into my app?


I have an app which uses iCloud Drive to store plain text files and it is working well -- I can save files to iCloud Drive and my app's folder shows up correctly and the files I created are there and they can be copied out, shared, etc….

I now want to enable the user to copy their own text files into my app folder using the Files app, but in the Files app the Move button is disabled whenever my app's folder is selected.

I've added an entry to CFBundleTypes in my info.plist:

<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>

and enabled file sharing and opening in place:

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

but that didn't make any difference. I've also tried adding an import declaration like this:

<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>

But that did not help either, even after restarting the iPhone. The Files app Move button turns gray whenever my app's folder is selected.

I suspect I might be on the wrong track and that this is really some sort of permissions problem, but I haven't seen anything about permissions in Apple's docs, just stuff about file types. On my Mac the folder shows up fine and I can drag files into it without any problem and my app recognizes them like it should. Only the iOS Files app won't save to my folder.

Does anyone have insight into how to enable copying text files into my app's folder in the Files app, or what might cause the Files app to refuse to move files in there?


Solution

  • I wrote to Apple dev support and received a very helpful reply. The short answer is to bump the app's build number in order to get iCloud to notice the changes, and it's important that the build number be higher than any previous build number (in other words don't just change it to another value, change it to a higher value).