2015-03-19 78 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文档解释了这一切。

相关问题