【问题标题】:Push notification in cordova在科尔多瓦推送通知
【发布时间】:2017-09-06 22:28:18
【问题描述】:

我正在使用cordova插件添加phonegap-plugin-push --variable SENDER_ID=XXXXXXXX 这个插件。并将以下代码添加到 javascript 文件中。

   function setupPush() {
   var push = PushNotification.init({
       "android": {
           "senderID": "XXXXXXXX"
       },
       "ios": {
         "sound": true,
         "alert": true,
         "badge": true
       },
       "windows": {}
   });

   push.on('registration', function(data) {
       console.log("registration event: " + data.registrationId);
       var oldRegId = localStorage.getItem('registrationId');
       if (oldRegId !== data.registrationId) {
           // Save new registration ID
           localStorage.setItem('registrationId', data.registrationId);
           // Post registrationId to your app server as the value has changed
       }
   });

   push.on('error', function(e) {
       console.log("push error = " + e.message);
   });
 }

它给出的错误是“TypeError:无法调用未定义的方法'init'”。

【问题讨论】:

  • 我的回答对您的问题有帮助吗?

标签: android cordova push-notification phonegap-plugins


【解决方案1】:

如果您在onDeviceReady 之后没有执行此操作,通常会发生这种情况。在此触发(推送通知、摄像头等)之前,您无法访问任何本机设备 API。

function onDeviceReady() {

    // Sets up your push notifications 
    setupPush();
}

// Fires when device is ready.
document.addEventListener("deviceready", onDeviceReady, false);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-24
    • 2016-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多