2013年3月2日土曜日

システム定義済みのドキュメントタイプ(UTI)登録


アプリケーションがオープンすることのできるファイルの種類は、plistにUTI(Uniform Type Identifiers)を登録することで設定できます。

mp3、m4aを登録する場合は、plistをProperty Listとしてオープンし、次のように設定します。

この設定を行うとm4a再生アプリ選択肢にこのアプリが追加されます。
例えばメールに添付されたm4aファイルをプレスするとファイルを開くアプリを選択することができますが、これに自分のアプリが含まれるようになります。

上記の設定のplistのSource Codeは次のようになります。
<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.mpeg-4-audio</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Audio</string>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>m4a</string>
        </array>
        <key>LSHandlerRank</key>
        <string>Default</string>
    </dict>
</array>

外部アプリから起動またはアクティブにされた場合は、UIApplicationDelegateの次のメソッドが呼ばれので、このファイルをオープンするように準備をします。

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation;

定義済みUTIリスト



0 件のコメント: