3

PhoneGap で (ネットワーク経由で) モバイル Web サイトをパッケージ化しています。PDF を指すリンクをインターセプトし、ChildBrowserプラグインを使用して開きたいと考えています。1 : ネイティブ コードからトリガーすることは可能ですChildBrowserか (どのリンクをインターセプトするかは既に決定しています) 2 :それを実行するのAppDelegate.m.shouldStartLoadWithRequest()適切な場所ですか? その場合: 3ChildBrowser :ネイティブ コードから正しく呼び出す方法は?

私はこの確かに素朴なアプローチを試しました:

return [self exec:@"ChildBrowserCommand.showWebPage",
      [url absoluteString]];

の行に沿ってエラーが発生しただけです...'NSInvalidArgumentException', reason: '-[AppDelegate exec:]: unrecognized selector sent to instance

(PS: このアプローチが理想的な方法ではないことは承知していますが、このプロジェクトは 2 日間の作業に対してのみ料金が設定されています)

4

2 に答える 2

7

プラグイン フォルダーに (子ブラウザー) プラグイン クラスを追加した場合は、appDelegate.m ファイルを操作する必要があります。#import "ChildBrowserViewController.h"
たとえば、html ファイルには次のような html/javascript コード
window.location="http://xyz.com/magazines/magazines101.pdf";
があります。子ブラウザーでこの URL を実行するには、shouldStartLoadWithRequest:PDF 拡張ファイルを含むリクエスト URLのネイティブメソッド。


/**
 * Start Loading Request
 * This is where most of the magic happens... We take the request(s) and process the response.
 * From here we can re direct links and other protocalls to different internal methods.
 */
- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    //return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
    NSURL *url = [request URL];
    if([request.URL.absoluteString isEqualToString:@"about:blank"])
        return [ super webView:theWebView shouldStartLoadWithRequest:request
                navigationType:navigationType ];
    if ([[url scheme] isEqualToString:@"gap"]) {
        return [ super webView:theWebView shouldStartLoadWithRequest:request
                navigationType:navigationType ];
    } else {
        NSString *urlFormat = [[[url path] componentsSeparatedByString:@"."] lastObject];
        if ([urlFormat compare:@"pdf"] == NSOrderedSame) {
            [theWebView sizeToFit];
            //This code will open pdf extension files (url's) in Child Browser
            ChildBrowserViewController* childBrowser = [ [ ChildBrowserViewController alloc ] initWithScale:FALSE ];
            childBrowser.modalPresentationStyle = UIModalPresentationFormSheet;
            childBrowser.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;   
            [super.viewController presentModalViewController:childBrowser animated:YES ];   
            NSString* urlString=[NSString stringWithFormat:@"%@",[url absoluteString]]; 
            [childBrowser loadURL:urlString];
            [childBrowser release];
            return NO;      
        } 
        else
            return [ super webView:theWebView shouldStartLoadWithRequest:request
                    navigationType:navigationType ];    
    } 
}

ありがとう、
マユル

于 2011-10-31T11:25:55.010 に答える