当前位置: 移动技术网 > 移动技术>移动开发>IOS > cordova 消息推送,告别消息推送服务器和苹果推送证书

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

2018年09月30日  | 移动技术网移动技术  | 我要评论

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

效果图:

\

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网