Amo*_*kar 18 html javascript objective-c ios
我们有一个应用程序,让我们调用它:xyz_app我有一个自定义URL方案的形式xyz_app://.
我们正在向用户发送电子邮件.
当他点击链接时,他想要去应用程序,如果没有安装应用程序,我们的移动网站.
所以从电子邮件中的链接,如何确保如果未安装该应用程序,该链接应该将用户发送到移动网站?
vfo*_*tta 26
只有在iDevice上安装了应用程序时,URL方案才能直接运行.如果没有安装,则会抛出错误.
1)要实现此功能,您必须从用户的电子邮件链接将用户重定向到将检测是否已安装应用程序的网页.像这样的东西www.yourwebsite/detectapp
2)您的detectapp页面将有一个javascript-
var appstoreFail = "www.your_redirect_website.com";
//Check is device is iOS
var iOS = /(iPad|iPhone|iPod)/.test(navigator.userAgent);
var appUrlScheme = "xyz_app://";
if (iOS) {
// If the app is not installed the script will wait for 2sec and redirect to web.
var loadedAt = +new Date;
setTimeout(function() {
if (+new Date - loadedAt < 2000)
window.location = appstoreFail;
} ,25);
// Try launching the app using URL schemes
window.open(appUrlScheme, "_self");
} else {
// Launch the website
window.location = appstoreFail;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11370 次 |
| 最近记录: |