cordova 消息推送,告別,消息推送服務器,和 蘋果推送證書


cordova plugin add org.apache.cordova.vibration

cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications

cordova plugin add cordova-plugin-websocket-server

 

手機端代碼:

var wsserver = 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();


效果圖:

我對小編確實無語了,解釋得多,代碼注釋多,就是亂寫一通

想要看詳細解釋

請看QQ日志:

http://user.qzone.qq.com/273237710/blog/1464765609

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM