2010-10-20 85 views
42

在iOS設備上,郵件應用程序爲附件提供「打開在...」選項。列出的應用程序已在操作系統中註冊了CFBundleDocumentTypes。我想知道的是我的應用程序可能允許用戶在其他應用程序中打開由我的應用程序生成的文件。 Mail是唯一提供此功能的應用程序嗎?在iOS應用程序中添加「打開在...」選項

+1

我敢肯定的答案在這裏:http://stackoverflow.com/questions/2774343/how-do-i-associate-file-types-with-an-iphone-application。 – 2011-12-13 16:55:26

+1

提供相關信息的更新文章現在可以在[文檔交互編程主題(http://developer.apple.com/library/ios/#documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/PreviewingandOpeningItems.html#//apple_ref/doc/uid/TP40010410-SW1「文檔交互編程主題「)。 – robotpukeko 2011-03-09 06:45:26

回答

36

看看Document Interaction Programming Topics for iOS: Registering the File Types Your App Supports

只要你在你的Info.plist提供您的文檔類型,識別文檔類型的其他應用程序將列出在他們的「打開」選擇你的應用程序。當然,這假定你的應用程序創建了其他應用程序可以打開的文檔。

+0

謝謝!這看起來像我正在尋找的東西。是的,我的應用程序創建.csv和.zip文件。 – westsider 2010-10-20 21:01:21

+0

你可能想要編輯你的答案以引用新的鏈接(顯然蘋果已經重組了iOS參考庫)。 – westsider 2011-03-09 16:29:39

+0

我在我的應用程序中添加了文檔類型。例如,我添加了類型PDF。但是當我運行文檔交互時,只需要快速查看應用程序。 – 2012-08-16 10:47:08

15

This是一個很棒的教程,幫助了我。

我已經添加了我的應用程序*.xdxf文件的支持。總之,你必須做兩件事。首先 - 這樣的條目添加到您的應用程序的Plist文件:

<key>CFBundleDocumentTypes</key> 
<array> 
    <dict> 
     <key>CFBundleTypeName</key> 
     <string>XDXF Document</string> 
     <key>LSHandlerRank</key> 
     <string>Owner</string> 
     <key>CFBundleTypeRole</key> 
     <string>Editor</string> 
     <key>LSItemContentTypes</key> 
     <array> 
      <string>com.alwawee.xdxf</string> 
     </array> 
    </dict> 
</array> 
<key>UTExportedTypeDeclarations</key> 
<array> 
    <dict> 
     <key>UTTypeDescription</key> 
     <string>XDXF - XML Dictionary eXchange Format</string> 
     <key>UTTypeConformsTo</key> 
     <array> 
      <string>public.text</string> 
     </array> 
     <key>UTTypeIdentifier</key> 
     <string>com.alwawee.xdxf</string> 
     <key>UTTypeTagSpecification</key> 
     <dict> 
      <key>public.filename-extension</key> 
      <string>xdxf</string> 
      <key>public.mime-type</key> 
      <string>text/xml</string> 
     </dict> 
    </dict> 
</array> 

在這裏,你應該添加UTExportedTypeDeclarations只有當你的文件類型是獨一無二的。或換句話說不是here

二 - 在AppDelegate處理委託方法:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 
{ 

    if (url != nil && [url isFileURL]) { 

     // xdxf file type handling 

     if ([[url pathExtension] isEqualToString:@"xdxf"]) { 

      NSLog(@"URL:%@", [url absoluteString]); 

     } 

    } 

    return YES; 
} 
+0

教程鏈接已損壞。 – 2015-06-28 12:45:53

4

爲了在所有文件「在打開的......」列表中可見,你需要添加到您的plist

<key>CFBundleDocumentTypes</key> 
<array> 
    <dict> 
     <key>CFBundleTypeName</key> 
     <string>Open All Files</string> 
     <key>LSHandlerRank</key> 
     <string>Owner</string> 
     <key>CFBundleTypeRole</key> 
     <string>Editor</string> 
     <key>LSItemContentTypes</key> 
     <array> 
      <string>public.content</string> 
      <string>public.data</string> 
     </array> 
    </dict> 
</array> 

一旦您的應用程序顯示爲「在......中打開」,則需要加載該文件。大多數網站顯示來實現這個功能:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject?) -> Bool 
{ 
    println("Open URL "+url.path!) 
} 

但這種功能運行良好的IOS在IOS 8.7崩潰我必須實現以下的功能,而不是得到它的工作。

func application(application: UIApplication, handleOpenURL url: NSURL) -> Bool 
{ 
    println("Open URL "+url.path!) 
} 
2

添加我的應用程序在「打開方式」列表成功如下,

Select info in YourAppName.target 添加一個新的文件類型過濾器,它的名字是你想要的東西和類型在https://developer.apple.com/library/ios/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html#//apple_ref/doc/uid/TP40009259-SW1

定義

希望你也能成功!

不過,我要實現的功能是「分享」像Facebook或鬆弛呢,我不能讓它還是......誰能給我一個大大的手:(

相關問題