与Safari的googlechrome://myurl.com等效

Val*_*rim 7 mobile mobile-safari ios web

我的webapp出现一些问题,如果用户单击Facebook应用程序中的链接,它将使用它自己的浏览器/ webview,但是必须使用Safari或Chrome才能运行该页面。

在研究(此问题)时,我发现您可以在Android设备上使用googlechrome:// navigate?url = example.com打开chrome,并在iOS上使用googlechrome://myurl.com来打开Chrome。如果用户的设备是iOS,则需要一种方法来打开Safari。

有办法吗?

附言:用户在Facebook中单击的链接将转到登录页面,该页面中有一个指向Web应用程序的按钮。当用户单击此按钮时,我将打开Chrome / Safari。

提前致谢!

rma*_*iar 1

SO 有一些类似主题的答案。类似的东西

NSString *yourUrl = @"http://yourURL";
SFSafariViewController *svc= [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString: yourUrl]];
[self presentViewController:svc animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

在斯威夫特中,那就是

let yourUrl = "http://www.yourURL.com";
let svc = SFSafariViewController.init(url: URL);
svc.delegate = self
present(svc, animated: true);
Run Code Online (Sandbox Code Playgroud)

应该管用。

如果您使用的是 Javascript,请查看使用 javascript 从 Web 应用程序强制在移动 Safari 中打开链接

看来你需要做类似的事情

HTML:

<div id="foz" data-href="http://www.google.fi">Google</div>
Run Code Online (Sandbox Code Playgroud)

JS:

document.getElementById("foz").addEventListener("click", function(evt) {
    var a = document.createElement('a');
    a.setAttribute("href", this.getAttribute("data-href"));
    a.setAttribute("target", "_blank");

    var dispatch = document.createEvent("HTMLEvents");
    dispatch.initEvent("click", true, true);
    a.dispatchEvent(dispatch);
}, false);
Run Code Online (Sandbox Code Playgroud)

在( http://www.hakoniemi.net/labs/linkkitesti.html)进行测试

资料来源:

在 Safari 而不是 UIWebVIew 中打开链接?

如何强制在 iOS Safari 中打开链接?

https://www.hackingwithswift.com/example-code/uikit/how-to-use-sfsafariviewcontroller-to-show-web-pages-in-your-app

使用 JavaScript 强制从 Web 应用程序在 Mobile Safari 中打开链接