![](/img/trans.png)
[英]how to prevent iOS safari alert when trying to open non-installed native app?
[英]How to open an app if installed through a webpage in Safari?
我們有一個應用程序,我們可以調用它: xyz_app
,我有一個xyz_app://
形式的自定義URL方案。
我們正在向用戶發送電子郵件。
當他點擊鏈接時,他想要去應用程序,如果沒有安裝應用程序,我們的移動網站。
所以從電子郵件中的鏈接,如何確保如果未安裝該應用程序,該鏈接應該將用戶發送到移動網站?
只有在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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.