2012-11-14 4 views
8

サイト用のラッパーアプリケーションを開発しています。基本的には、UIWebViewでモバイル版のサイトを開きます。サイトの一部のリンクはPDFを指しています。UIWebViewに「Open in iBooks」を追加します

Safariで同じサイトを開き、PDFへのリンクをタップすると、「iBooksで開く」という素晴らしい黒いストライプがPDF上に表示されます。下の画像のように:

enter image description here

は、どのように私は私のアプリで同じ見てストライプを実装するだろうか?

編集:私はは、半透明の背景に黒のボタンを作成する方法についての質問ではない

ています。

私はワークフロー全体の再生に興味を持っています:とのiBooksアプリ(または任意の他のPDFビューア)の場合のみがある場合PDF

  • ストライプ(ビュー)に

    • ユーザーがナビゲートは、をポップアップインストールされます。
    • ポップアップでボタンをタップすると、そのアプリにドキュメントが転送され、アプリが開きます。
  • +0

    VIEW(ストライプ?)やボタンの機能:

    は、必要に応じて、次のデリゲートメソッドを実装することができますか? –

    +0

    @ Daij-Djan質問 – Bobrovsky

    +0

    のアップデートをご覧ください.DjkはibooksのURLスキーム –

    答えて

    24

    のiBooksは、あなたが呼び出すことができますインストールされているかどうかを確認するには、次の

    BOOL iBooksInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"ibooks://"]]; 
    

    はあなたがアプリケーションのリスト(なぜだけのiBookには限界?;)を提示することができます)を使用して:

    //use the UIDocInteractionController API to get list of devices that support the file type 
    NSURL *pdfURL = // your pdf link. 
    UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:pdfURL]; 
    
    //present a drop down list of the apps that support the file type, click an item in the list will open that app while passing in the file. 
    [docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES]; 
    

    をPDFを読み込むアプリを作っていない限り、これはiOSシミュレータでは機能しません。

    実際にPDFをiBooksで開くことができるようにする場合は、ファイルのURLを@ "ibooks://"スキームまたは他の2つのスキームのいずれかに追加してみてください@ "itms-books://"と@ "itms-bookss://"であるiBooksが提供するもの(iBook Storeの本のために働くが、それが他のURLでも使えるかどうかはわからない)。私は偉大な例hereを見つけた私の問題を修正ソリューションについて

    NSURL *iBooksURLScheme = [NSURL URLWithString:@"ibooks://"]; 
    NSString *fileURLString = // your file URL as *string* 
    NSURL *finalURL = [iBooksURLScheme URLByAppendingPathComponent:fileURLString]; 
    
    [[UIApplication sharedApplication] openURL:finalURL]; 
    
    +0

    詳細な回答ありがとうございます。 – Bobrovsky

    +0

    これは古い質問ですが、ARCでこの方法を使用するとエラーが発生します。 self.docInteractionController = [UIDocumentInteractionController interactControllerWithURL:url]; –

    +1

    ちょっとした注意:UIDocumentInteractionControllerのURLは、ローカル、ファイルURL(PDFをUIWebViewにダウンロードするのに使用されていない)でなければなりません。したがって、ダウンロードしたpdfデータを最初にpdf拡張子(あなたのドキュメントディレクトリに最適)で保存し、[NSURL fileURLWithPath:pdfPath]でURLを作成する必要があります。 – Lukasz

    1

    (私の前の答えは、コードが含まれていなかったとして再度回答謝罪。)

    :あなたは、その後のような何かを行うことができます。

    私はそれを切り取って貼り付けて、誰かを助けます。あなたのクラスはViewControllerを呼ばれると仮定すると、absoluteripple.com

    への完全な信用は、その後、ViewController.hファイルに:

      
    @interface ViewController : UIViewController 
                { 
                    UIDocumentInteractionController *docController; 
                } 
    

    のViewControllerで次のメソッドを追加します。M: // - UIDocumentInteractionコントローラを設定し、我々は//

    - (UIDocumentInteractionController *) setupControllerWithURL:(NSURL *)fileURL 
                                                   usingDelegate:(id <UIDocumentInteractionControllerDelegate>)         interactionDelegate { 
        
                UIDocumentInteractionController *interactionController = 
                [UIDocumentInteractionController interactionControllerWithURL:fileURL]; 
                interactionController.delegate = interactionDelegate; 
        
                return interactionController; 
                } 
    

    コールバックイベントを処理できるように、自己へのデリゲートを設定する - ここで重要なインスタンスメソッドはpresentOptionsMenuFromBarBUttonItem は//です - BarButtonItem呼ば_btnActionsがあることを想定している

      
    
        - (void)showOptionsMenu 
                { 
                    NSURL *fileURL = [NSURL fileURLWithPath:@"THE_FILE_URL_PATH"]; 
                    docController = [self setupControllerWithURL:fileURL 
                                           usingDelegate:self]; 
                    bool didShow = [docController presentOptionsMenuFromBarButtonItem:_btnActions 
                                                                     animated:YES]; 
                    if (!didShow) { 
                            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" 
                                                                message:@"Sorry. The appropriate apps are not found on this device." 
                                                               delegate:nil 
                                                      cancelButtonTitle:@"OK" 
                                                      otherButtonTitles: nil]; 
                            [alert show]; 
                    } 
                } 
    
    1. あなたはこの例では にファイルを送ることができるアプリケーションを表示したいとき、UIBarButtonは以下のIBActionsまで配線されている上記を呼び出すメソッドを追加します。
     
        - (IBAction)ActionButtonClicked:(id)sender { 
                [self showOptionsMenu];} 
    

    ことをそれは...ですか。ボタンをクリックすると、ファイルを送信できるアプリケーション(あれば)を示すアクションシートが表示されます(AppleのUIDocumentInteractionControllerクラスで動作します)。

    - (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application 
    
    - (void)documentInteractionController:(UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application 
    
    - (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller 
    
    関連する問題