How do I register a custom filetype in iOS

时光总嘲笑我的痴心妄想 提交于 2019-11-26 10:36:21

问题


I am currently creating a app in which i want to let the user backup their files (plist + m4a). I zip the files and change the extension to a custom one (specifically for my app, say \"*.MyBackup\"). The user can then either export via email or with iTunes file sharing.

I have already read about CFBundleDocumentTypes but didn\'t really get what I had to do with them.

The part where i am currently stuck at is how to associate my extension with my app. If the user sends himself an email with the \"custom\"-zip file he\'s supposed to be able to open it with my app.

How do I do this and what are \"UTExportedTypeDeclarations\"?


回答1:


I hope it's okay if I dump in that part of my projects info.plist without much further explanation. I think it's pretty much self-explanatory.

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array>
            <string>Icon-iPad-doc320.png</string>
            <string>Icon-iPad-doc.png</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>MyAppName File</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <!-- my app supports files with my custom extension (see UTExportedTypeDeclarations) -->
            <string>com.myurl.myapp.myextension</string>
            <!-- and csv files. -->
            <string>public.comma-separated-values-text</string>
        </array>
    </dict>
</array>



<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>MyAppName File</string>
        <key>UTTypeIdentifier</key>
        <string>com.myurl.myapp.myextension</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>myextension</string>
            <key>public.mime-type</key>
            <string>application/octet-stream</string>
        </dict>
    </dict>
</array>



回答2:


Check out /var/mobile/Library/Preferences/com.apple.LaunchServices.plist



来源:https://stackoverflow.com/questions/4186401/how-do-i-register-a-custom-filetype-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!