2015-03-19 70 views
0

我必須設計一個iOS應用程序,它將下載一個pdf文件,並將有一個「打開」UIActivityViewControllerUIActivity子類)。使用OpenUrl我發送數據到其他應用程序,我可以得到pdf數據第二申請對於iOS應用程序打開

但我想要Safari也有同樣的功能。我想在safari「open in」中看到第二個應用程序,並且一旦用戶在Safari中獲得一些pdf,用戶可以點擊打開以獲取pdf數據第二個應用程序

- (void)performActivity { 

    NSString *[email protected]"ran/jan/jena/getit"; 
    NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"ranjantest:///%@",urlstring]]; 
    BOOL checkurl=[[UIApplication sharedApplication]canOpenURL:URL]; 
    if(checkurl){ 
     [[UIApplication sharedApplication] openURL:URL]; 
    }else{ 
     UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"" message:@"No suitable App installed" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 
    } 

} 

任何建議如何做到這一點?

+0

你有沒有看過'UIDocumentInteractionController'(https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDocumentInteractionController_class/)這我相信可以讓你下載你的PDF或選擇一個已經存儲在設備上,併爲您提供可讓您查看該PDF的應用程序。您可以使用'interactionControllerWithURL:'打開PDF文檔,然後使用'Presenting and Dismissing Menus'中的一個向用戶展示可用選項 – Popeye 2015-03-19 09:22:04

+0

您的應用需要註冊並處理自定義URL方案。看看蘋果文件在這裏:https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html – Kilogen9 2015-03-19 09:25:13

+0

但我想看到我的第二個應用程序在Safari 「打開」。使用openurl將數據從一個應用程序發送到其他應用程序可以正常工作。但是我想在safari中打開一些pdf,並且從safari「open in」需要打開我的第二個可以接收pdf數據的應用程序。希望我的問題清楚 – ranjanjena12345 2015-03-19 09:33:46

回答

0

好吧,讓您的應用程序出現在Safari瀏覽器的open in/with選項中,您需要做的就是將您的應用程序設置爲與xcode中的特定文檔類型關聯。

在信息選項卡中,您將添加一個文檔類型並指定PDF,這將使您的應用程序與PDF文檔相關聯,所以當您前往Safari瀏覽器並下載PDF文檔時,它將允許您使用open in/with選項並選擇您的應用程序。

請仔細閱讀Apple Documentation for Document Type here,但從外觀上看,您可能仍需要實施UIDocumentInteractionController,但Apple文檔解釋了這一切。

相關問題