美文网首页
cordova 消息推送,告别,消息推送服务器,和 苹果推送证书

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

作者: 蜗牛_96f2 | 来源:发表于2018-05-31 17:53 被阅读205次

    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://' ]

    });

    后台代码处理:

    varport =this.Request.Params["Port"];

    var addr =this.Request.Params["Addr"];

    varwebSocketClient =newWebSocket(string.Format("ws://{0}:{1}",addr ,port ));

    webSocketClient.open();

    stringmessage ="万恶的苹果你等着!";

    webSocketClient.Send(message);

    webSocketClient.close();

    效果图:

    我对小编确实无语了,解释得多,代码注释多,就是乱写一通

    想要看详细解释

    请看QQ日志:

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

    相关文章

      网友评论

          本文标题:cordova 消息推送,告别,消息推送服务器,和 苹果推送证书

          本文链接:https://www.haomeiwen.com/subject/xafcsftx.html