Exclusive iOS UTI
Asked Answered
C

1

8

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>
Centaury answered 7/10, 2012 at 14:5 Comment(3)
As soon as you specify that your file format conforms to public.png or public.jpeg or similar, all apps that specify that they can open files of these UTIs will be able to open them. If you remove your UTTypeConformsTo array, that should solve your problem.Rysler
In other words, don't specify that your com.photoapp.exclusive conforms to com.photoapp.photo. Leave com.photoapp.photo as is, and just don't specify any conformance for com.photoapp.exclusive.Rysler
Thanks! Do you want to make that a comment so that I can accept your answer?Centaury
R
5

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.

Rysler answered 13/10, 2012 at 12:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.