独特的iOS UTI

8

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

基本上,如果其他应用程序想要能够在已注册拍照的任何应用程序中打开照片,则希望com.photoapp.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];
    }

以下是我应用程序的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>

1
只要您指定文件格式符合 public.pngpublic.jpeg 或类似的标准,所有指定可以打开这些 UTI 文件的应用程序都能够打开它们。如果您删除了 UTTypeConformsTo 数组,那么这个问题就会解决。 - Greg
1
换句话说,不要指定你的 com.photoapp.exclusive 符合 com.photoapp.photo。保持 com.photoapp.photo 不变,只是不为 com.photoapp.exclusive 指定任何符合性。 - Greg
谢谢!您想把它变成评论,这样我就可以接受您的答案了吗? - joshholat
1个回答

5

一旦你指定了一个如public.pngpublic.jpeg这样的UTI,所有指定可以打开这些类型文件的应用程序都将能够打开你的文件。因此,如果在你的com.photoapp.exclusive UTI中完全未指定任何类型一致性,则不会有应用程序支持它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接