Ionic framework PushNotification未定义(ng cordova)

Ionic framework PushNotification未定义(ng cordova),ionic-framework,cordova-plugins,ngcordova,Ionic Framework,Cordova Plugins,Ngcordova,在我的ionic应用程序中,当在浏览器中运行应用程序时,我遇到以下错误 ng-cordova.js:6378 Uncaught ReferenceError: PushNotification is not defined 在我的控制台中,以及当我为android构建应用程序并在我的手机中运行时,它在那里也不起作用,即没有弹出窗口 对于注册Id:警报(data.registrationId) app.run(function($ionicPlatform, $cordovaPushV5) {

在我的ionic应用程序中,当在浏览器中运行应用程序时,我遇到以下错误

ng-cordova.js:6378 Uncaught ReferenceError: PushNotification is not defined 
在我的控制台中,以及当我为android构建应用程序并在我的手机中运行时,它在那里也不起作用,即没有弹出窗口 对于注册Id:
警报(data.registrationId)

app.run(function($ionicPlatform, $cordovaPushV5) {
  $ionicPlatform.ready(function() {

      // For Push Notification

     var options = {
        android: {
          senderID: "121XXXXXXX49"
        },
        ios: {
          alert: "true",
          badge: "true",
          sound: "true"
        }
      };

      // initialize
      $cordovaPushV5.initialize(options).then(function() {
        // start listening for new notifications
        $cordovaPushV5.onNotification();
        // start listening for errors
        $cordovaPushV5.onError();

        // register to get registrationId
        $cordovaPushV5.register().then(function(data) {
          // `data.registrationId` save it somewhere;
          alert(data.registrationId);
        })
      });

      // triggered every time notification received
      $rootScope.$on('$cordovaPushV5:notificationReceived', function(event, data){
        alert(data.title + ' - '+ data.message);
        // data.message,
        // data.title,
        // data.count,
        // data.sound,
        // data.image,
        // data.additionalData
      });

      // triggered every time error occurs
      $rootScope.$on('$cordovaPushV5:errorOcurred', function(event, e){
        alert(e.message);
        // e.message
      });  

  });

})

如果您查看ngCordova页面,就会发现“Cordova插件在您的浏览器中开发时不起作用”。这就是它不能在浏览器中工作的原因

请参见此处的链接:

在初始化插件之前,您应该检查应用程序是否在设备上运行(不在浏览器中),以及爱奥尼亚平台是否准备就绪。那么,如果你按照正确的链接,你是好去

链接:

我个人的建议是,你不必使用ng cordova,因为有了新的phonegap推送插件。你不需要使用任何其他东西。您基本上可以在不使用ng cordova的情况下执行以下操作

确保您检查了爱奥尼亚平台是否已准备就绪,且该平台不是浏览器。

var pushConfig = {
    android: {
        senderID: "blabla"
    },
    ios: {
        alert: true,
        badge: true,
        sound: true
    }
};

var push = window.PushNotification.init(pushConfig);

push.on('registration', function(data) {
    var token = data.registrationId
    console.log('OK: register notfy ', token);
});

详细信息如下:

如果您查看ngCordova页面,会发现“Cordova插件在您的浏览器中开发时无法工作”。这就是它不能在浏览器中工作的原因

请参见此处的链接:

在初始化插件之前,您应该检查应用程序是否在设备上运行(不在浏览器中),以及爱奥尼亚平台是否准备就绪。那么,如果你按照正确的链接,你是好去

链接:

我个人的建议是,你不必使用ng cordova,因为有了新的phonegap推送插件。你不需要使用任何其他东西。您基本上可以在不使用ng cordova的情况下执行以下操作

确保您检查了爱奥尼亚平台是否已准备就绪,且该平台不是浏览器。

var pushConfig = {
    android: {
        senderID: "blabla"
    },
    ios: {
        alert: true,
        badge: true,
        sound: true
    }
};

var push = window.PushNotification.init(pushConfig);

push.on('registration', function(data) {
    var token = data.registrationId
    console.log('OK: register notfy ', token);
});

详细信息如下:

我的操作与您所说的完全相同,但当我在andriod phone中运行应用程序时,我没有获得重分类ID。您遇到了什么错误?你能提供更多的细节吗@gudboisgni已经在$rootScope.regId中分配了data.registrationId,当我用{{regId}将它打印到视图中时。它只是空的@orhankutluCan您是否可以首先尝试console.log(data.registrationId),如我在回答中所示?在浏览器中,我得到:PushNotification未定义,android手机如何查看console.log()数据@或者Hankutlui做的和你说的完全一样,但是当我在andriod手机上运行应用程序时,我没有得到重新发布ID。你得到了什么错误?你能提供更多的细节吗@gudboisgni已经在$rootScope.regId中分配了data.registrationId,当我用{{regId}将它打印到视图中时。它只是空的@orhankutluCan您是否可以首先尝试console.log(data.registrationId),如我在回答中所示?在浏览器中,我得到:PushNotification未定义,android手机如何查看console.log()数据@奥汉库特鲁