gpt4 book ai didi

iphone - 我可以格式化 URL 以从应用程序的 UIWebView 中启动 Safari 吗?

转载 作者:行者123 更新时间:2023-12-03 20:34:54 25 4
gpt4 key购买 nike

我的应用程序有一个 UIWebView,可以显示大量内容。对于其中一些内容,我想退出应用程序,并启动 Safari 来处理 Web 内容,而不是在我的 UIWebView 中执行。是否有一种 url 格式可以显式启动 Safari 而不是在 UIWebView 中加载页面?

显然我不能使用 http://因为它只是打开 URL。我可以使用 safari://或类似的东西吗?

编辑:抱歉,我最初并不清楚。我正在寻找一种解决方案,涉及更改页面上的网址而不对我的客户端进行修改。希望 native Safari 启动模式与手机的 tel://类似。

最佳答案

当然。然后只需让 UIWebView 委托(delegate)执行以下操作:

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

关于iphone - 我可以格式化 URL 以从应用程序的 UIWebView 中启动 Safari 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4505189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com