独家iOS UTI

jos*_*lat 8 iphone uti ios uidocumentinteraction instagram

我正在尝试为我的iOS应用程序创建/导出独有的UTI类型(非常类似于Instagram独家处理UTI com.instagram.exclusivegram的方式).

基本上,我想com.photoapp.photo是一个应用程序可以使用,如果他们希望能够在任何注册拍照的应用程序中打开照片(类似于Instagram的com.instagram.photo).然后我想com.photoapp.exclusive只能在我的应用程序中打开(类似于com.instagram.exclusivegram).

我在设备上遇到的是即使使用com.photoapp.exclusive,UIDocumentController也会提示我在PhotoApp或DropBox中打开它,它应该只是PhotoApp.

我有我的应用程序注册UTI以及我用来检查开放能力的示例应用程序.我在示例应用程序中使用的代码如下:

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"photoapp://"]]) {
        NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"derp.png"], 1.0);
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *fullPathToFile = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"photoapp.pae"];
        [imageData writeToFile:fullPathToFile atomically:NO];

        interactionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:[NSString stringWithFormat:@"file://%@", fullPathToFile]]];
        interactionController.UTI = @"com.photoapp.exclusive";
        interactionController.delegate = self;

        [interactionController presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES];
    }
Run Code Online (Sandbox Code Playgroud)

以下是我的app文件中的plist文件:

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeDescription</key>
        <string>Exclusive PhotoApp Photo</string>
        <key>UTTypeConformsTo</key>
        <array>
            <string>com.photoapp.photo</string>
        </array>
        <key>UTTypeIdentifier</key>
        <string>com.photoapp.exclusive</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>pae</string>
        </dict>
    </dict>
    <dict>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>pa</string>
        </dict>
        <key>UTTypeIdentifier</key>
        <string>com.photoapp.photo</string>
        <key>UTTypeDescription</key>
        <string>PhotoApp Photo</string>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.png</string>
            <string>public.jpeg</string>
        </array>
    </dict>
</array>
<key>UIFileSharingEnabled</key>
<true/>
<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.photoapp.exclusive</string>
            <string>com.photoapp.photo</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Photo</string>
        <key>LSHandlerRank</key>
        <string>Default</string>
    </dict>
</array>
Run Code Online (Sandbox Code Playgroud)

Gre*_*reg 5

只要您指定UTI(例如public.png或)public.jpeg,指定可以打开这些类型的文件的所有应用程序都可以打开您的文件.因此,如果您未在com.photoapp.exclusiveUTI中指定任何类型一致性,则不会显示任何应用程序支持它.