欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

cordova 消息推送,告别消息推送服务器和苹果推送证书

程序员文章站 2023-08-24 09:13:39
cordova 消息推送,告别消息推送服务器和苹果推送证书。 cordova plugin add org.apache.cordova.vibration cordova plugin add h...

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();

效果图:

cordova 消息推送,告别消息推送服务器和苹果推送证书