Associate Audio and Video Types with iPhone app

冷暖自知 提交于 2020-01-06 02:40:07

问题


I am trying to make an app that will receive media files from the Mail app by using Long Press > Open in "My app"

I am having trouble associating the files types I want with my app. I am using the Uniform Type Identifiers Reference

This is what my info.plist looks like:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>mp3</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>MP3 Audio</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.mp3</string>
        </array>
        <key>LSTypeIsPackage</key>
        <false/>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>avi</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>AVI movie</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.avi</string>
            <string>video/x-msvideo</string>
        </array>
        <key>LSTypeIsPackage</key>
        <false/>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>3gp</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>3GPP movie</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.3gpp</string>
            <string>application/octet-stream</string>
        </array>
        <key>LSTypeIsPackage</key>
        <false/>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>mpg4</string>
            <string>mp4</string>
            <string>m4v</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>MPEG-4 content</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.mpeg-4</string>
            <string>video/mp4</string>
            <string>video/mp4v</string>
        </array>
        <key>LSTypeIsPackage</key>
        <false/>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>mov</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>QuickTime movie</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.apple.quicktime-movie</string>
            <string>video/quicktime</string>
        </array>
        <key>LSTypeIsPackage</key>
        <false/>
    </dict>
</array>

Out of these, only Mp3 and AVI show the Open In "My app" option. I just get the "Save Video" option that adds the videos to my camera roll. What am I doing wrong?

The formats I want to associate are: AVI, 3GP, MP4, M4V, MOV.

I have also tried this. It works for MP3, WAV, AVI, FLV but still no go for 3GP, MP4, MOV, M4V

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Audio</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.audio</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Video</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.movie</string>
        </array>
    </dict>
</array>

回答1:


SO answer to How do I associate file types with an iPhone application?, shows some examples that differ from yours only very slightly. the content of this file looks like it should work, though there are some redundancies according to the documentation:

  • CFBundleTypeExtensions is MacOS only, and even then, it is redundant and ignored if LSItemContentTypes is present.
  • LSTypeIsPackage is MacOS only, and even then, it is redundant and ignored if LSItemContentTypes is present.
  • the documentation recommends using a uniform type identifier for CFBundleTypeName . e.g. for mp4, rather than use MPEG-4 content as you have, instead, try public.mpeg-4 (internally kUTTypeMPEG4)

still, while i think the cleanup would be a good idea, i think only the last one of these may have a real chance of solving your problem, because the other two should just get ignored.

… which means what i think may actually solve your problem is cleaning your app off the device and out of your cache, quitting xcode, and then re-opening your project, re-building, and running it again. i have experienced problems where Xcode and its deployment mechanism get confused when putting resources on the device. performing this cleanup may straighten things out if some attempt at registration initially failed before you got to this point.




回答2:


I have installed other apps (e.g TeamViewer, oPlayer etc) that also support Document importing.. They too dont show up in the "Open As .." Action Sheet for the Mail app for MOV, 3GP, M4V etc.

I am guessing that apple doesnt allow some files to be opened by 3rd party apps and wants them handled internally. So all the user can do is save them to the Camera Roll.

The only options that remains is to add functionality to our apps to allow selecting videos from the camera roll. So, Mail > Save Video > Camera Roll > 3rd Party App

What a bummer.

My Final entries in Info.plist

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Audio</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.audio</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Video</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.3gpp</string>
            <string>public.3gpp2</string>
            <string>public.mpeg-4</string>
            <string>public.avi</string>
            <string>com.apple.quicktime-movie</string>
            <string>public.mpeg</string>
            <string>public.movie</string>
        </array>
    </dict>
</array>

I am still hoping there is some way around this.. anyone?



来源:https://stackoverflow.com/questions/11523723/associate-audio-and-video-types-with-iphone-app

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