自定义UTI未在App中打开(Custom UTI Not opening in App)

编程入门 行业动态 更新时间:2024-10-25 12:21:29
自定义UTI未在App中打开(Custom UTI Not opening in App)

我正在尝试为我的应用创建一个新文档UTI,以便人们可以与他人分享兴趣点。 从我能理解的SO,Tutorials和Apple的文档中,您需要执行以下操作:

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

根据我的理解,只要你做对了,你应该可以通过Mail打开文件而不会有任何问题。 不幸的是,它不适用于我自己的自定义UTI。 我在Mail中看到我的应用程序在“打开...”列表中,但是当我选择它时,我的应用程序根本无法打开。 它不仅在应用程序未打开时,而且在应用程序打开时都不做任何事情。 邮件保持不变,完全没有任何反应。 我还使用“组织者”检查了控制台,这绝对没有发生。

最初我以为我的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>

UTExportedTypeDeclarations:

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

非常感谢任何帮助! -标记

I am trying to create a new document UTI for my App so that people can share points of interest with others. From what I can understand on SO, Tutorials, and from Apple's documentation, you need to do the following:

Create a Document Type in the .plist Create an Exported UTI that corresponds with it Use the method: -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

From what I understand, as long as you did those right, you should be able to open the file through Mail without any problems. Unfortunately it isn't working for my own custom UTIs. I DO see my App in the list of "Open with..." in Mail, but when I select it, my App doesn't open at all. It just dosen't do anything at all not only when the App isn't open, but when the App is open. Mail stays up and nothing happens at all. I also checked the console using "Organizer" and there is absolutely nothing that happens.

Originally I thought my plist was wrong, so I tested opening a public UTI (I added the com.adobe.pdf document type) and my app launched just fine (though it promptly crashed because I don't actually support PDFs ;)). But the point was that it launched without any problem.

The only thing I can think of that might be a problem is HOW I am creating the file. I am creating the file in an email by the use of this method (also in the App to export):

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];

Is there anything wrong with that?

Also, here is my plist code:

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>

UTExportedTypeDeclarations:

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

Thanks a lot for any help!! -Mark

最满意答案

我最终通过拉开所有的代码来弄清楚什么是错的。

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

关于为什么会发生的任何想法?

I finally figured out what was wrong by pulling apart all the code.

When I change "public.filename-extension" to a string and not an array of strings it works. Don't ask me why... I think it's strange we can't use an array of file extensions. But apparently that was it.

Any ideas as to why that happened?

更多推荐

本文发布于:2023-04-27 15:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1327203.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   UTI   App   Custom   opening

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!