我有一个应用正在升级到 iOS5 SDK 和 Phonegap 1.0.0
Childbrowser 插件工作正常,但是当单击 iTunes 应用程序商店的链接时 - 该链接会在 Childbrowser 窗口中打开。
我更希望它直接在 Appstore 中打开,如果我不使用 ChildBrowser 插件就会出现这种情况。
这是应用商店链接(指向应用商店内的提交评论页面)
这就是 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/