ios 什么是 Mobile Safari 的自定义 URL Scheme?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22642223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is Mobile Safari's custom URL Scheme?
提问by Ryan
iOS URL Schemes allow web sites to launch apps like so:
iOS URL Schemes 允许网站像这样启动应用程序:
twitter://timeline
launches Twittergooglechrome://google.com
launches Chromefb://root
launches Facebook______________
launches Safari? (nothttp://
, since Safari won't launch fromUIWebView
)
twitter://timeline
推出推特googlechrome://google.com
启动 Chromefb://root
推出脸书______________
启动 Safari?(不是http://
,因为 Safari 不会从 启动UIWebView
)
What custom url scheme triggers Safari to launch (even from within another app's UIWebView
)?
什么自定义 url 方案会触发 Safari 启动(甚至从另一个应用程序的UIWebView
)?
To clarify, I'm not looking for [[UIApplication sharedApplication] openURL: request.URL];
澄清一下,我不是在寻找 [[UIApplication sharedApplication] openURL: request.URL];
Instead I'm looking for how a website can allow a user to launch Mobile Safari from within the UIWebView
of another app (Google Chrome, Twitter, etc.).
相反,我正在寻找网站如何允许用户从UIWebView
另一个应用程序(谷歌浏览器、Twitter 等)中启动 Mobile Safari 。
Example HTML links that pop open other apps:
弹出打开其他应用程序的示例 HTML 链接:
<a href="twitter://timeline">Open Twitter</a>
<a href="googlechrome://google.com">Open site in Chrome</a>
<a href="fb://root">Open Facebook</a>
I'm looking for something similar to these non-working examples:
我正在寻找类似于这些非工作示例的内容:
<a href="safari://google.com">Open Safari [Doesn't work]</a>
<a href="webkit://google.com">Open Webkit [Doesn't work]</a>
Here's a jsFiddleof the same: http://jsfiddle.net/gXLjF/9/embedded/result/
这是相同的jsFiddle:http: //jsfiddle.net/gXLjF/9/embedded/result/
Try opening this URLin iOS Google Chrome and opening Safari with the links.
尝试在 iOS Google Chrome 中打开此 URL并使用链接打开 Safari。
回答by TomSwift
There is no Safari URL scheme. If you make one up and use it in your html you can check for it though.
没有 Safari URL 方案。如果你制作一个并在你的 html 中使用它,你可以检查它。
Implement the UIWebViewDelegate
method webView:shouldStartLoadWithRequest:navigationType:
. Return 'NO' for the requests that you want to shunt to mobile safari. Call UIApplication
openURL
with the request's URL.
实现UIWebViewDelegate
方法webView:shouldStartLoadWithRequest:navigationType:
。对于要分流到移动 safari 的请求,返回“NO”。UIApplication
openURL
使用请求的 URL调用。
Something like this:
像这样的东西:
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
// all clicked links!
if ( navigationType == UIWebViewNavigationTypeLinkClicked )
{
[[UIApplication sharedApplication] openURL: request.URL];
return NO;
}
// or, custom URL scheme!
if ( [request.URL.scheme isEqualToString: @"my-open-in-safari"] )
{
// remap back to http. untested!
NSURL* url = [NSURL URLWithString: [request.URL.absoluteString stringByReplacingOccurrencesOfString: @"my-open-in-safari" withString: @"http" ]];
[[UIApplication sharedApplication] openURL: url];
return NO;
}
return YES;
}
回答by Sergey Nikitin
As for any web-browser, http://someurl.com
and https://someurl.com
.
至于任何网络浏览器,http://someurl.com
以及https://someurl.com
.