3

アプリにPDFファイルを表示しています。同じpdfを開くことができるiPhoneにインストールされたアプリを表示するnagbarに「開く」オプションを表示したいのですが、ユーザーがいずれかのアプリ(pdfビューアなど)を選択すると、pdfはpdfビューアアプリで開く必要があります。

どうすればよいですか?

助けてください

前もって感謝します。

4

3 に答える 3

4

デバイスで使用可能なアプリケーションでファイルを開くには、UIDocumentInteractionControllerクラスを使用します。

ドキュメント インタラクション コントローラーは、デリゲート オブジェクトと共に、ローカル システム内のファイルとのユーザー インタラクションを管理するためのアプリ内サポートを提供します。たとえば、電子メール プログラムはこのクラスを使用して、ユーザーが添付ファイルをプレビューし、他のアプリで開くことを許可する場合があります。このクラスを使用して、指定したファイルをプレビュー、開く、コピー、または印刷するための適切なユーザー インターフェイスを提供します。

行き詰まった場合、SOには多くの質問があります。UIDocumentInteractionController の検索結果

于 2013-01-31T01:47:18.097 に答える
3

このコードは、探している OpenIn インタラクションを表示します。iPhone と iPad で動作します。iPad ではポップオーバーになっています。私はPDFを生成していますが、あなたが持っているものだけを使用している場合は、writeToFileを必要とせず、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];
}
于 2013-01-31T16:38:38.503 に答える
1

「UIDocumentInteractionController」のApple Default APIで確認できます。

以下はURLです:

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIDocumentInteractionController_class/Reference/Reference.html

問題が解決することを願っています。

乾杯。

于 2013-01-31T06:59:32.437 に答える