如何將文件發送到不同的應用程序,以瞭解應用程序支持哪個UTI?可以說文件沒有文件擴展名,但我碰巧知道文件的UTI。UIDocumentInteractionController,但沒有文件擴展名但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
,不會被調用的應用程序就不會切換。
目標應用出口其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
,它可以工作。但是,應用程序列表顯示了所有其他支持相同文件擴展名的應用程序,無論UTI I型電源如何。
說我宣佈在2級不同的應用2個尿路感染:
App1 with UTI1: com.mycomp.a with extension .abc
App2 with UTI2: com.mycomp.b with extension .abc
當文件遞給了DocumentInteractionController,以及UTI設置爲com.mycomp.a
它也將顯示應用2作爲一種可能的應用程序能夠處理的文件。
我通過以下方式定義的尿路感染擴展名爲:
<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中顯示應用程序。
謝謝
我找到了一個更簡單的解決方案。 「willBeginSendingToApplication:」中的代碼在成功調用open菜單後可以執行,這就消除了調用方法的必要性! – Jan
請爲此提供代碼。我嘗試設置名稱屬性,但它不反映在第三方應用程序。 – slott
是的,詳細的*真實*解決方案將是最有幫助的。 – buildsucceeded