簡體   English   中英

獨家iOS UTI

[英]Exclusive iOS UTI

我正在嘗試為我的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];
    }

這是我的應用程序的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>

一旦指定了UTI(例如public.pngpublic.jpeg ,所有指定可以打開這些類型的文件的應用程序都將能夠打開您的文件。 因此,如果您在com.photoapp.exclusive UTI中根本沒有指定任何類型一致性,那么似乎沒有應用程序會支持它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM