我正在尝试为我的应用程序创建一个新的文档 UTI,以便人们可以与他人分享兴趣点。根据我对 SO、Tutorials 和 Apple 文档的理解,您需要执行以下操作:
- 在 .plist 中创建文档类型
- 创建与其对应的导出 UTI
- 使用方法:-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
据我了解,只要您做对了,您应该可以通过Mail打开文件而没有任何问题。不幸的是,它不适用于我自己的自定义 UTI。我确实在邮件的“打开方式...”列表中看到了我的应用程序,但是当我选择它时,我的应用程序根本没有打开。它根本不做任何事情,不仅在应用程序未打开时,而且在应用程序打开时。邮件保持不变,根本没有任何反应。我还使用“Organizer”检查了控制台,绝对没有发生任何事情。
最初我认为我的 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];
这有什么问题吗?
另外,这是我的 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>
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>
非常感谢您的帮助!!-标记