我的应用程序有一个显示相当数量内容的UIWebView.对于某些内容,我想退出应用程序,并启动Safari来处理Web内容,而不是在我的UIWebView中执行.是否有一个url格式将显式启动Safari而不是在UIWebView中加载页面?
显然我不能使用http://因为它只是打开了url.我可以使用safari://或类似的东西吗?
编辑:道歉,我原来不清楚.我正在寻找一种解决方案,涉及在不修改我的客户端的情况下更改页面上的URL.希望通过tel://为手机启用本机Safari启动模式.
当然.然后让UIWebView代表做:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString * customScheme = @"safari";
NSURL * loadURL = [request URL]; //this is the url the user tapped
if ([[loadURL scheme] isEqual:customScheme]) {
//if the url starts with "safari://"
NSString * absoluteURL = [loadURL absoluteString];
//replace "safari" with "https"
absoluteURL = [absoluteURL stringByReplacingCharactersInRange:NSMakeRange(0,[customScheme length]) withString:@"https"];
NSURL * openURL = [NSURL URLWithString:absoluteURL];
//open the URL in MobileSafari
[[UIApplication sharedApplication] openURL:openURL];
//tell your UIWebView to ignore this request
return NO;
} else {
//this is not a safari:// url, so handle it normally
return YES;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
446 次 |
| 最近记录: |