Javascript 创建一个链接来启动 iOS 应用程序或重定向到应用程序商店
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4671634/
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
Create a link that either launches iOS app, or redirects to app store
提问by Silromen
Possible Duplicate:
Is it possible to register a http+domain-based URL Scheme for iPhone apps, like YouTube and Maps?
I have a custom URL scheme for my iOS app, and I want to be able to email a link to someone that will either launch the app if it's on the device, or take them to the app store if they don't have it.
我有一个适用于我的 iOS 应用程序的自定义 URL 方案,并且我希望能够通过电子邮件将链接发送给某人,如果该应用程序在设备上,则该链接将启动该应用程序,或者如果他们没有该应用程序,则将他们带到应用程序商店。
I'd like to be able to send myapp://someurl and have that either launch or go to myapp on the appstore, but I don't think this will work out of the box.
我希望能够发送 myapp://someurl 并启动或转到 appstore 上的 myapp,但我认为这不会开箱即用。
Instead, I'm thinking of creating a link that loads some javascript which will try myapp://someurl, and if that fails will instead load the app store link.
相反,我正在考虑创建一个加载一些 javascript 的链接,该链接将尝试 myapp://someurl,如果失败将加载应用商店链接。
My javascript knowledge is crappy. I can set window.location to perform the redirect, but there doesn't seem to be a way to catch errors from that in order to perform another action if that fails.
我的 javascript 知识很糟糕。我可以设置 window.location 来执行重定向,但似乎没有办法从中捕获错误以便在失败时执行另一个操作。
Anyone know how to do this?
有人知道怎么做吗?
回答by David Vaccaro
window.launchsockPicker = function() {
setTimeout(function() {
window.location = 'http://myDomain.com/install-app.cfm'
}, 500);
window.location = 'myApp://?context=someVariableIfNeeded';
};
回答by TomSwift
There is no good way to achieve this. You can launch an app via a URL but there is no way to test whether an app is installed first.
没有好的方法可以实现这一点。您可以通过 URL 启动应用程序,但无法测试是否先安装了应用程序。