自定义 UTI 未在应用程序中打开

Kiv*_*olf 5 types document objective-c uti ios5

我正在尝试为我的应用程序创建一个新文档 UTI,以便人们可以与他人分享兴趣点。根据我对 SO、教程和 Apple 文档的了解,您需要执行以下操作:

  1. 在 .plist 中创建文档类型
  2. 创建与其对应的导出 UTI
  3. 使用方法:-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

据我所知,只要你做对了,你应该能够通过邮件打开文件而不会出现任何问题。不幸的是,它不适用于我自己的自定义 UTI。我确实在邮件的“打开方式...”列表中看到了我的应用程序,但是当我选择它时,我的应用程序根本没有打开。不仅在应用程序未打开时,而且在应用程序打开时,它都不做任何事情。邮件保持正常,什么也没有发生。我还使用“组织者”检查了控制台,绝对没有发生任何事情。

最初我认为我的 plist 是错误的,所以我测试了打开一个公共 UTI(我添加了 com.adobe.pdf 文档类型)并且我的应用程序启动得很好(尽管它很快崩溃了,因为我实际上并不支持 PDF ;))。但关键是它启动时没有任何问题。

我唯一能想到的可能是我如何创建文件的问题。我正在使用此方法(也在要导出的应用程序中)在电子邮件中创建文件:

MFMailComposeViewController *picker = [[[MFMailComposeViewController alloc] init] autorelease];
[picker setSubject:[NSString stringWithFormat:@"My place: %@",POIName]];
[picker addAttachmentData:customPOIData mimeType:@"application/customPOI" fileName:[NSString stringWithFormat:@"%@.icp",POIName]];
[picker setMessageBody:@"Check out this great place I found!" isHTML:NO];
[picker setMailComposeDelegate:self];
[self presentModalViewController:picker animated:YES];
Run Code Online (Sandbox Code Playgroud)

有什么问题吗?

另外,这是我的 plist 代码:

CFBundleDocumentTypes:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array/>
        <key>CFBundleTypeName</key>
        <string>Custom POI</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.imadev.icp</string>
        </array>
    </dict>
</array>
Run Code Online (Sandbox Code Playgroud)

UTExportedType 声明:

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>Custom POI</string>
        <key>UTTypeIdentifier</key>
        <string>com.imadev.icp</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <array>
                <string>icp</string>
            </array>
            <key>public.mime-type</key>
            <string>application/customPOI</string>
        </dict>
    </dict>
</array>
Run Code Online (Sandbox Code Playgroud)

非常感谢您的帮助!!-标记

Kiv*_*olf 2

我终于通过拆解所有代码找出了问题所在。

当我将“public.filename-extension”更改为字符串而不是字符串数组时,它可以工作。不要问我为什么......我认为我们不能使用文件扩展名数组很奇怪。但显然就是这样。

关于为什么会发生这种情况有什么想法吗?