3

PhoneGap と JQuery モバイルを使用して作成した iOS アプリがあります。アプリには、モバイル サファリで開きたい外部リンクがいくつかありますが、現時点ではアプリ ビューで開くだけです。リンクは次のように書かれています。

<a rel="external" href="wwww.example.com">Click Here</a>

私はJQueryモバイルのドキュメントを読んだところ、追加rel="external"するとこれは解決するが、どうやら解決しないと書かれていました。何か案は?これは HTML ベースのアプリであることに注意してください。

4

2 に答える 2

9

最後に、 MainviewController.m に移動し、他の投稿で言及されているように webView に言及しているセクションを探し、それをこれから変更することでそれを行うことができました

/* Comment out the block below to over-ride */

/*

- (void) webViewDidStartLoad:(UIWebView*)theWebView
{
    return [super webViewDidStartLoad:theWebView];
}

- (void) webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error
{
    return [super webView:theWebView didFailLoadWithError:error];
}

- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}
*/

これに

/**

 * 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

{

    NSURL *url = [request URL];

    // add any other schemes you want to support, or perform additional

    // tests on the url before deciding what to do -jm

    if( [[url scheme] isEqualToString:@"http"] ||

       [[url scheme] isEqualToString:@"https"])

    {

        [[UIApplication sharedApplication] openURL:url];

        return NO;

    }

    else

    {

        return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];

    }



}

私はobjective-cの経験がないので、これを試してみる必要があったので、うまくいったことをうれしく思います。

于 2013-02-28T19:52:01.160 に答える
1

Nice は私を少し助けてくれましたが、リンクを自動的に開きます:

if (navigationType == UIWebViewNavigationTypeLinkClicked) { 
}

ユーザーが http:// または https:// を含む URL をクリックすると、サファリで開くようになりました。

完全に私はこのコードを得ました:

if (navigationType == UIWebViewNavigationTypeLinkClicked) {
if( [[url scheme] isEqualToString:@"http"] ||

   [[url scheme] isEqualToString:@"https"])

{

    [[UIApplication sharedApplication] openURL:url];

    return NO;

}

else

{

    return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];

}
}
于 2013-06-01T11:07:32.790 に答える