2011-11-01 76 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