【问题标题】:Open In For iOS App在 iOS 应用中打开
【发布时间】:2015-05-22 07:33:39
【问题描述】:

我必须设计一个 iOS 应用程序,它将下载一个 pdf 文件,并且将有一个由 UIActivityViewControllerUIActivity 子类化)“打开”。使用 OpenUrl 我将数据发送到另一个应用程序,我可以在第二个应用程序中获取 pdf 数据。

但我也希望 Safari 具有相同的功能。我想在 safari “打开方式”中查看 第二个应用程序,一旦用户在 Safari 中获得一些 pdf,用户可以单击打开以在 第二个应用程序中获取 pdf 数据。

- (void)performActivity {

    NSString *urlstring=@"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];
    }

}

有什么建议吗?

【问题讨论】:

  • 你看过UIDocumentInteractionController (developer.apple.com/library/ios/documentation/UIKit/Reference/…) 我相信这可以让你下载你的pdf或选择一个已经存储在设备上的pdf,并为你提供应用程序,让你查看该pdf。您可以使用 interactionControllerWithURL: 打开 PDF 文档,然后使用 Presenting and Dismissing Menus 之一向用户显示可用选项
  • 您的应用需要注册和处理自定义 URL 方案。在此处查看 Apple 文档:developer.apple.com/library/ios/documentation/iPhone/Conceptual/…
  • 但我想在 safari 中看到我的第二个应用程序“打开方式”。使用 openurl 将数据从一个应用程序发送到另一个应用程序可以正常工作。但我想在 safari 中打开一些 pdf,并且从 safari “打开方式”需要打开我的第二个可以接收 pdf 数据的应用程序。希望我的问题很清楚

标签: ios objective-c uiactivity


【解决方案1】:

确定让您的应用程序出现在 safari for PDFs 的 open in/with 选项中,您需要做的是将您的应用程序设置为与 xcode 中的特定文档类型相关联。

在“信息”选项卡中,您将添加文档类型并指定 PDF,这会将您的应用程序与 PDF 文档相关联,因此当您进入 safari 并下载 PDF 文档时,您可以使用 open in/with 选项并选择您的应用。

阅读Apple Documentation for Document Type here,但从外观上看,您可能仍需要实现UIDocumentInteractionController,但Apple Document 说明了一切。

【讨论】:

    猜你喜欢
    • 2016-09-29
    • 2013-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多