0

我有一个应用程序正在升级到 iOS5 SDK 和 Phonegap 1.0.0

Childbrowser 插件工作正常,但是当单击 iTunes 应用商店的链接时 - 该链接会在 Childbrowser 窗口中打开。

我希望它直接在 Appstore 中打开,如果我不使用 ChildBrowser 插件会发生这种情况。

这是应用商店链接(指向应用商店中的提交评论页面)

http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=386470812&pageNumber=0&sortOrdering=1&type=Purple+Software&mt=8

这就是 AppDelegate 的修改方式

AppDelegate.m,向下滚动并替换以下内容:

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

有了这个:

- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:
(NSURLRequest *)request navigationType:
(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
if ([[url scheme] isEqualToString:@"gap"] || [url isFileURL]) {
return [ super webView:theWebView shouldStartLoadWithRequest:request
navigationType:navigationType ];
}
else {
ChildBrowserViewController* childBrowser =
[ [ ChildBrowserViewController alloc ] initWithScale:FALSE ];
[super.viewController presentModalViewController:childBrowser
animated:YES ];
[childBrowser loadURL:[url description]];
[childBrowser release];
return NO;
}
}

我使用这篇博文中概述的方法来启动并运行 Childbrowser http://iphonedevlog.wordpress.com/2011/09/24/installing-childbrowser-into-xcode-4-with-phonegap-1-0-mac -os-x-雪豹/

关于如何改变它以产生所需动作的任何想法?

非常感谢..

4

1 回答 1

2

您需要使用方法和属性检查您的 URL 是否包含http://itunes.apple.com/作为子字符串。 请确认您的 javascript 调用了这样的 url,rangeOfString:location

window.location="http://itunes.apple.com/us/app/code-check-basic-free-medical/id386470812?mt=8";
或者您可以使用任何 jquery 方法。
请用shouldStartLoadWithRequest:以下代码段替换方法。

/**
 * 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];
  if ([[url scheme] isEqualToString:@"gap"] || [url isFileURL]) {
    return [ super webView:theWebView shouldStartLoadWithRequest:request
            navigationType:navigationType ];
  }
  else {
    //here we will check whether urlString has http://itunes.apple.com/ as substring or not
    NSString* urlString=[url absoluteString];
    if ([urlString rangeOfString:@"http://itunes.apple.com/"].location == NSNotFound){
      ChildBrowserViewController* childBrowser = [ [ ChildBrowserViewController alloc ] initWithScale:FALSE ];
      childBrowser.modalPresentationStyle = UIModalPresentationFormSheet;
      childBrowser.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;   
      [super.viewController presentModalViewController:childBrowser animated:YES ];   
      [childBrowser loadURL:urlString];
      [childBrowser release];
      return NO;      
    }
    else 
      return YES;      
  }
}

谢谢,
马尤尔

于 2011-11-04T05:31:17.333 回答