What is Mobile Safari's custom URL Scheme? [duplicate]

纵然是瞬间 提交于 2019-12-30 01:37:08

问题


iOS URL Schemes allow web sites to launch apps like so:

  • twitter://timeline launches Twitter
  • googlechrome://google.com launches Chrome
  • fb://root launches Facebook
  • ______________ launches Safari? (not http://, since Safari won't launch from UIWebView)

What custom url scheme triggers Safari to launch (even from within another app's UIWebView)?

To clarify, I'm not looking for [[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.).

Example HTML links that pop open other apps:

<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 jsFiddle of the same: http://jsfiddle.net/gXLjF/9/embedded/result/

Try opening this URL in iOS Google Chrome and opening Safari with the links.


回答1:


There is no Safari URL scheme. If you make one up and use it in your html you can check for it though.

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.

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



回答2:


As for any web-browser, http://someurl.com and https://someurl.com.



来源:https://stackoverflow.com/questions/22642223/what-is-mobile-safaris-custom-url-scheme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!