什么是Mobile Safari的自定义URL方案? [英] What is Mobile Safari's custom URL Scheme?

查看:253
本文介绍了什么是Mobile Safari的自定义URL方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS网址计划允许网站启动以下应用:

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


  • twitter:// timeline 推出Twitter

  • googlechrome://google.com 推出Chrome

  • fb:// root 启动Facebook

  • ______________ 启动Safari? (不是 http:// ,因为Safari不会从 UIWebView 启动)

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

什么自定义网址方案触发Safari启动(即使是在另一个应用的 UIWebView 中)?

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

为了澄清,我不是在寻找 [[UIApplication sharedApplication] openURL:request.URL];

To clarify, I'm not looking for [[UIApplication sharedApplication] openURL: request.URL];

相反,我正在寻找一个网站如何允许用户从另一个应用程序的 UIWebView 中启动Mobile Safari(Google Chrome,推特等。)

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.).

打开其他应用程序的示例HTML链接:

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>

这是一个相同的jsFiddle http://jsfiddle.net/gXLjF/9/embedded/result/

尝试在iOS中打开此网址谷歌浏览器并使用链接打开Safari。

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

推荐答案

没有Safari URL方案。如果你在你的html中使用它,你可以检查它。

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

实现 UIWebViewDelegate 方法 web视图:shouldStartLoadWithRequest:navigationType:。对于要分流到移动野生动物园的请求,请返回否。使用请求的URL调用 UIApplication openURL

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像这样:

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

这篇关于什么是Mobile Safari的自定义URL方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆