一、push通過H5+實現
簡單實現方式:通過輪詢服務器是否有新消息推送過來
mui.plusReady(function() {
plus.navigator.closeSplashscreen();
//關閉等待框
plus.nativeUI.closeWaiting();
//顯示當前頁面
plus.webview.currentWebview().show();
document.getElementById("btn").addEventListener('tap',function(){
plus.push.clear()//清除掉所有的推送消息,清空系統消息中的所有信息
})
document.getElementById("btn1").addEventListener('tap',function(){
plus.push.createMessage("測試消息", "LocalMSG", {cover:false});//創建本地消息,這個可以通過判斷服務器端是否有新消息推送,獲取到推送消息之后,創建本地推送消息
})
plus.push.addEventListener( "click", function(msg){alert( "推送事件監聽You clicked: " + msg.content );}, false );//監聽系統消息點擊,click為從系統消息中心點擊啟動應用程序,或者receive應用從推送服務器接收到推送消息事件
});
plus.push.getAllMessage()//獲取所有的推送消息
plus.push.getClientInfo()//獲取客戶端標識信息
測試出現:測試時使用定時器推送多條消息的時候,系統消息欄還是只顯示一個,退出應用程序的時候,不再推送消息
var ua = navigator.userAgent.toLowerCase();
if (/iphone|ipad|ipod/.test(ua)) {
//alert("iphone");
} else if (/android/.test(ua)) {
alert("android");
}//判斷手機是安卓還是iPhone
二.使用個推