简体   繁体   English

独家iOS UTI

[英]Exclusive iOS UTI

I'm trying to create / export an exclusive UTI type for my iOS app (very similar to how Instagram exclusively handles the UTI com.instagram.exclusivegram). 我正在尝试为我的iOS应用创建/导出独家UTI类型(非常类似于Instagram专门处理UTI com.instagram.exclusivegram的方式)。

Basically, I want com.photoapp.photo to be what an app can use if they want to be able to open the photo in any app registered for taking photos (similar to Instagram's com.instagram.photo). 基本上,我希望com.photoapp.photo可以用作应用程序,如果他们希望能够在注册用于拍照的任何应用程序中打开照片(类似于Instagram的com.instagram.photo)。 Then I want com.photoapp.exclusive to only be able to open in my app (similar to com.instagram.exclusivegram). 然后,我希望com.photoapp.exclusive仅能在我的应用程序中打开(类似于com.instagram.exclusivegram)。

What I'm running into on my device is that even when using com.photoapp.exclusive, the UIDocumentController prompts me to open it in either PhotoApp or DropBox where it should just be PhotoApp. 我在设备上遇到的问题是,即使使用com.photoapp.exclusive,UIDocumentController也会提示我在PhotoApp或DropBox中将其打开,而它们应该只是PhotoApp。

I have my app that registers the UTI as well as an example app I'm using to check on the opening ability. 我有注册UTI的应用程序以及用于检查打开功能的示例应用程序。 The code I'm using in the example app is below: 我在示例应用程序中使用的代码如下:

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];
    }

And here is what I have in my plist file for my 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>

As soon as you specify a UTI such as public.png or public.jpeg , all apps that specify that they can open files of these types will be able to open your file. 一旦指定了UTI(例如public.pngpublic.jpeg ,所有指定可以打开这些类型的文件的应用程序都将能够打开您的文件。 So, if you do not specify any type conformance at all in your com.photoapp.exclusive UTI, no apps will appear to support it. 因此,如果您在com.photoapp.exclusive UTI中根本没有指定任何类型一致性,那么似乎没有应用程序会支持它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM