1.登錄OpenInstall網站,這里會為你創建一個AppKey,而這個東西在web頁面會用到。
2.在推廣頁面中加入推廣下載。
<script type="text/javascript"> var data = OpenInstall.parseUrlParams();//openinstall.js中提供的工具函數,解析url中的所有查詢參數 new OpenInstall({ appKey: '@(appKey)', preferWakeup: true, onready: function () { var m = this, button = document.getElementById("downloadButton"), downApp = document.getElementsByClassName("downapp"); button.style.visibility = "visible"; button.onclick = function () { check(m); } for (var i = 0; i < downApp.length; i++) { var btn = downApp[i]; btn.onclick = function () { check(m); } } } }, data); function check(obj) { var ua = navigator.userAgent.toLowerCase(), iphoneos = (ua.match(/iphone os/i) == "iphone os") || (ua.match(/iph os/i) == "iph os") || (ua.match(/ipad/i) == "ipad"); var guid = document.querySelector('.guid'); if (iphoneos) { location.href = "/Home/IOSDownLoad"; } else { /*在app已安裝的情況嘗試拉起app*/ obj.schemeWakeup(); /*用戶點擊某個按鈕時(假定按鈕id為downloadButton),安裝app*/ obj.wakeupOrInstall(); return false; } } </script>
這里的推廣頁面地址也可以使用短連接實現,請看我的另一篇文章。