Phonegap Plugin Push& Node-gcm NotRegistered

时间:2016-09-29 00:35:47

标签: javascript android node.js cordova phonegap-plugins

所以我在这里见过有关此问题的其他人。我所拥有的一切似乎都没有。以下是我的问题的步骤:

1)我将Ionic app安装到手机上。

2)使用谷歌控制台设置我的发件人密钥和API密钥。 3)创建了我的node-gcm服务器。

4)使用我的phonegap-plugin-push设备令牌向手机发送通知。

5)卸载了我的应用

6)重新安装了应用程序。

7)尝试发送通知,现在我收到了GCM的NotRegistered错误。

我交叉检查了我的所有密钥:服务器,发件人,设备。全部正确。我无法弄清楚为什么重新安装应用程序后,我收到一个未注册的错误。以下是我使用的工具: 离子框架,Android手机,NodeJS服务器,Node-gcm,google开发控制台,phonegap-plugin-push

最后,代码:



.run(function($ionicPlatform, $ionicPopup, $rootScope, $http, $state) {
  $ionicPlatform.ready(function() {
    var push = PushNotification.init({
        android: {
          senderID: "7821....1490",
			    sound: "true",
			    vibration: "true"
        },
        browser: {
            pushServiceURL: 'http://push.api.phonegap.com/v1/push'
        },
        ios: {
            alert: "true",
            badge: true,
            sound: "true",
			      vibration: "true",
			      clearBadge: true
        },
        windows: {}
    });
    push.on('registration', function(data) {
        console.log("Device Token: " + data.registrationId);
        $rootScope.devToken = data.registrationId;
    })






var message = new gcm.Message();
				message.addData('title', 'Alert');
				message.addData('message', 'Message From: '+ messageUser + '\n' + 'Message Text: ' + messageText);
				//message.addData('image', image);
				sender.send(message, android, function (err, response) {
					if(err) {}
        			else {
						console.log(response.results);
						//response is NotRegistered, unregister devices
						for (var i = 0; i < response.results.length; i++) {
							if (response.results[i].error == 'NotRegistered') {
								console.log("ERROR");
							}
						}
					}    
				});
&#13;
&#13;
&#13;

我愿意和你一起解决这个问题。只要知道,我已经检查了所有密钥,并且所有密钥都是正确的。当我重新安装应用程序时,我得到了一个新的设备令牌,我正在尝试推送到新的设备令牌。

1 个答案:

答案 0 :(得分:2)

OK!对于任何有这个问题的人,请在这里阅读!

使用推送插件,在应用程序卸载。它不会清除所有数据。我将设备令牌存储在范围变量中并将其存储在本地存储中。在应用程序卸载时,请在卸载前转到设置并清除所有数据。重新安装后,您将获得一个新令牌,它应该可以正常工作!