cordova 消息推送,告别消息推送服务器和苹果推送证书
cordova 消息推送,告别消息推送服务器和苹果推送证书。
cordova plugin add org.apache.cordova.vibration
cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications
cordovapluginaddcordova-plugin-websocket-server
手机端代码:
varwsserver=cordova.plugins.wsserver;wsserver.start(1818, {
// websocket server
'onstart' : function(addr, port) {
$.post(“test.ashx”,{addr:addr,port:port},function(json){alert("注册到服务器端成功!");},“josn”);
},
'onmessage' : function(conn, msg) {
cordova.plugins.notification.local.schedule({
id: 1,
title: "来自服器(websocket客户端的消息)",
text:msg,
//firstat: monday_9_am,
every: "week",
//icon: "",
data: { meetingid:"123" }
});
navigator.notification.vibrate(1000);
cordova.plugins.notification.local.on("click", function (notification) {
alert(notification.data+",messageid:"+notification.data.meetingid);
});
},
'onclose' : function(conn, code, reason) {
console.log('a user disconnected from %s', conn.remoteaddr);
},
'origins' : [ 'file://' ]
});
后台代码处理:
var port = this.request.params["port"];
var addr = this.request.params["addr"];
var websocketclient = new websocket(string.format("ws://{0}:{1}",addr ,port ));
websocketclient.open();
string message = "万恶的苹果你等着!";
websocketclient.send(message);
websocketclient.close();
效果图:
上一篇: 小儿咳嗽的表现 日常需要怎样护理