与其他应用一起打开pdf [英] Open pdf with other apps

查看:99
本文介绍了与其他应用一起打开pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用中显示pdf文件。我想在唠叨栏上显示打开方式选项,显示安装在iPhone上的应用程序可以打开相同的pdf,如果用户选择任何应用程序(例如pdf查看器),那么pdf应该使用pdf viewer app打开。

I am displaying a pdf file in an app. I want to show "open with" option on nag bar showing apps installed on iPhone that can open same pdf and if user selects any of the app (for e.g. pdf viewer) then the pdf should get open with pdf viewer app.

我该怎么办?

请帮助

在此先感谢。

推荐答案

此代码将显示您正在寻找的OpenIn交互。它适用于iPhone和iPad。在iPad上它是一个popover。我正在生成PDF,但如果您只是使用了一个,则不需要写入文件,只需提交文件路径。

This code will present the OpenIn interaction you're looking for. It works for iPhone and iPad. On iPad its in a popover. I'm generating the PDF but if you're just using one you have you don't need to writeToFile, just hand in the filePath.

// In your header. MyViewController.h
@interface MyViewController : UIViewController <UIDocumentInteractionControllerDelegate>
{
    UIDocumentInteractionController *docController;
}

// In your implementation. MyViewController.m Open Results is hooked up to a button.
- (void)openResults
{
    // Generate PDF Data.
    NSData *pdfData = [self makePDF];

    // Create a filePath for the pdf.
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"Report.pdf"];

    // Save the PDF. UIDocumentInteractionController has to use a physical PDF, not just the data.
    [pdfData writeToFile:filePath atomically:YES];

    // Open the controller.
    docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
    docController.delegate = self;
    docController.UTI = @"com.adobe.pdf";
    [docController presentOpenInMenuFromBarButtonItem:shareButton animated:YES];
}

这篇关于与其他应用一起打开pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆