2011-11-01 71 views
0

我在升级到iOS5的的SDK和PhoneGap的1.0.0PhoneGap/iOS - 如何让Childbrowser忽略与Appstore的链接?

的Childbrowser插件正常工作过程中的应用程序,但被点击iTunes应用程序商店的链接时 - 该链接在Childbrowser开业窗口。

我宁愿它直接在Appstore中打开,如果我不使用ChildBrowser插件,会发生什么情况。

这是AppStore的链接(指向提交AppStore上的复审页)

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/

如何改变这种以产生所需的行动有什么想法?

非常感谢..

回答

2

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

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

感谢,
MAYUR