iphone - PhoneGap/iOS - 如何让 Childbrowser 忽略指向 Appstore 的链接?

标签 iphone objective-c ios cordova phonegap-plugins

我有一个应用正在升级到 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-snow-leopard/

关于如何改变它以产生所需的 Action 有什么想法吗?

非常感谢..

最佳答案

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

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;      
  }
}

谢谢,
马约尔

关于iphone - PhoneGap/iOS - 如何让 Childbrowser 忽略指向 Appstore 的链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7971010/

相关文章:

objective-c - 许多应用程序在 iO 中使用一个商店

ios - 未收到随机主队列调度

ios - 导入多张原始分辨率为: low memory warning issue的图片

ios - 在 header 字段中设置 Cookie

ios - iPhone编程: How do I make a UIImage in a UIImageView show at actual size?

iPhone - 是否可以覆盖静音模式或通过推送通知发出递归警报声?

iphone - UIScrollView 自定义分页大小

ios - 从从 firebase 检索数据的闭包中获取数据

iphone - 从嵌套数组中删除对象

ios - 在 Firebase 身份验证 Xamarin 中访问 UID 时出错