如何知道应用程序支持哪个 UTI 将文件发送到不同的应用程序?假设该文件没有文件扩展名,但我碰巧知道该文件的 UTI。
我尝试了以下方法:
// target is a NSURL with the location of the extension less file on the system
// knownUTI is a NSString containing the UTI of the file
UIDocumentInteractionController* dic = [UIDocumentInteractionController interactionControllerWithURL:target];
[dic retain];
dic.delegate = self;
dic.UTI = knownUTI;
[dic presentOpenInMenuFromRect:CGRectZero inView:superController.view animated:YES]
它显示支持的应用程序,但是,如果我选择它,它不会切换应用程序。代表打电话给
- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application
但
- (void)documentInteractionController:(UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application
永远不会被调用,并且应用程序永远不会切换。
目标 App 以如下方式导出其 UTI:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>Migration DocType</string>
<key>CFBundleTypeRol</key>
<string>Shell</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.mycomp.customstring</string>
</array>
</dict>
</array>
...
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>My custom UTI</string>
<key>UTTypeIdentifier</key>
<string>com.mycomp.customstring</string>
</dict>
</array>
由于这不起作用,我还尝试添加自定义扩展。不过,它不会以这种方式工作。将自定义扩展名添加到我移交给的文件时DocumentInteractionController
,它可以工作。但是,应用程序列表显示了支持相同文件扩展名的所有其他应用程序,无论 I 提供的 UTI 类型如何。
假设我在 2 个不同的应用程序中声明了 2 个 UTI:
App1 with UTI1: com.mycomp.a with extension .abc
App2 with UTI2: com.mycomp.b with extension .abc
当将文件交给 DocumentInteractionController 并将 UTI 设置为com.mycomp.a
它时,也会将 App2 显示为能够处理文件的可能应用程序。
我以以下方式定义了一个带有扩展名的UTI:
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>My UTI Type</string>
<key>UTTypeIdentifier</key>
<string>com.mycomp.a</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>abc</string>
<key>public.mime-type</key>
<string>application/abc</string>
</dict>
</dict>
</array>
我真的很感谢你的帮助,我有点卡住了。所以,又是一个问题:如何将文件发送到具有已知 UTI 的应用程序,或者没有扩展名,或者与我不想在 DocumentInteractionController 中将应用程序显示为选项的其他文件具有相同的扩展名?
谢谢