簡介我有一個應用程序具有正常運行的URL方案,我希望從存儲在主屏幕上的Web應用程序啟動該應用程序,而普通的JavaScript重定向方法似乎不起作用。詳細信息我正在嘗試創建一個iOS Web應用程序,該應用程序將從保存在主屏幕上的鏈接以全屏模式打開。Web應用程序需要打開特定的本機應用程序。我已經為本機應用程序注冊了url方案,并驗證了該方案是否可以正常工作-例如,我可以通過直接在Safari地址欄中鍵入該方案來打開本機應用程序。我也可以使用的+openURL:方法從其他應用程序中打開它UIApplication。我還想使用可以添加到主屏幕的本地Web應用程序中的某些參數打開它。我想要做的是像在本機應用程序中那樣使用JavaScript:window.location = "myapp://myparam";在網絡應用中使用此代碼時,我會收到一條警告:“無法打開myWebAppName-無法打開myWebAppName。錯誤是“無法顯示此URL”?!?。在Safari中執行時,同樣的JavaScript可以正常工作。我使用會得到相同的結果window.location.replace("myapp://myparam")。該Web應用程序的html是:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>untitled</title> <meta name="generator" content="TextMate http://macromates.com/"> <meta name="author" content="Carl Veazey"> <!-- Date: 2012-04-19 --> <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" /> <meta name="apple-mobile-web-app-capable" content="yes" /> <meta names="apple-mobile-web-app-status-bar-style" content="black-translucent" /></head><body> <script type="text/javascript" charset="utf-8"> if (window.navigator.userAgent.indexOf('iPhone') != -1) { if (window.navigator.standalone == true) { window.location = "myapp://myparam"; } else { document.write("please save this to your home screen"); };} else { alert("Not iPhone!"); document.location.href = 'please-open-from-an-iphone.html'; }; </script></body></html>我在這里做錯了什么?我對JavaScript和移動網絡缺乏經驗,所以我懷疑我只是缺少明顯的東西。
如何從Web應用程序打開本機iOS應用程序
江戶川亂折騰
2019-11-15 17:03:19