Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

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). Then I want com.photoapp.exclusive to only be able to open in my app (similar to 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.

I have my app that registers the UTI as well as an example app I'm using to check on the opening ability. 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:

<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>
like image 546
joshholat Avatar asked Oct 07 '12 14:10

joshholat


1 Answers

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. So, if you do not specify any type conformance at all in your com.photoapp.exclusive UTI, no apps will appear to support it.

like image 183
Greg Avatar answered Oct 12 '22 08:10

Greg