为什么我无法通过离子框架接收Android上的推送通知 [英] Why am I unable to receive push Notification on Android by ionic framework

查看:267
本文介绍了为什么我无法通过离子框架接收Android上的推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了这个小测试应用程序以测试新的离子推进和后端我使用谷歌Android云信息服务。我正在从Android GCM成功在我的前端

I had written this small test app to test the New ionic push and in the backend I am using Android Google Cloud Messaging Service. I am getting success from the android GCM in my frontEnd

data: Object
canonical_ids: 0
failure: 0
multicast_id: 8830892721591033000
results: Array[1]
success: 1
__proto__: Object

这是前端code

app.run(function($ionicPlatform, $ionicPush,$http) {
  $ionicPlatform.ready(function() {
   $ionicPush.init({
  "onNotification": function(notification) {
    var payload = notification.payload;
    console.log(payload);
    console.log(notification);
  },
  "onRegister": function(data) {
    console.log(data.token);
  }
});

$ionicPush.register(function(data){
  var reg = {
    regId : data.token
   };
  $http.post('http://app.example.com/sendPushNot', reg)
  .then(function(response){
    console.log(response);
  }, function (error){
    console.log(error);
  });
});

在我的后端

var message = new gcm.Message({
    collapseKey: 'demo',
    priority: 'high',
    contentAvailable: true,
    delayWhileIdle: true,
    timeToLive: 3,
    //restrictedPackageName: "somePackageName",
    dryRun: false,
    data: {
        key1: 'message1',
        key2: 'message2'
    },
    notification: {
        title: "Hello, World",
        icon: "ic_launcher",
        body: "This is a notification that will be displayed ASAP."
    }
});

    console.log(message);
    var sender = new gcm.Sender('AIzaSyB9Lz**********9mHJuH5if1m5k5JOVMw'); 

    var regTokens =  [];
    regTokens.push(req.body.regId);

        sender.send(message, { registrationTokens: regTokens }, function (err, result) {
            if (err) {
                console.error(err);
            }
            else {

                 console.log(result);
                 res.status(200);
                 res.set('Content-Type', 'text/html');
                 res.send(result);
            }
        });   

但还是我无法接收任何推送通知。我不理解为什么?

but still I am unable to receive any push Notification. I am not understanding the reason why?

任何其他人点什么。我使用的节点GCM 在后端

Any anybody else spot anything. I am using node-gcm in the backend

编辑编辑修改结果
这个问题可能是任何地方的服务器或前端。结果
我有整整缩小使用这个问题的范围。现在用这个,因为没有有效载荷我能看到 onNotification 监听器控制台日志。这意味着我的听众是正确的......部分,因为我能够从服务器发送的数据只使用数据领域的前端。
现在的问题可能是Ionic.Push无法接收通知,或者可能是该节点-GCM不能正确地发送插件
看哪,你对我的这些坏蛋插件之间的终极对决气息。

EDIT EDIT EDIT
The problem could be anywhere server or frontEnd.
I have exactly narrowed down the scope of the problem using this. Now using this as there is no payload I am able to see the console logs in onNotification listener. It means My listener is correct... partially as I am able to send the data from server to Frontend by using only data field. Now the problem could be that Ionic.Push is not capable of receiving the notifications or could be that node-gcm is not able to send the plugins correctly Behold your breath for the ultimate showdown between me and these badass plugins.

推荐答案

好了,这家伙它去,我的最后的对决后,我是赢家。我终于想通了。我还没有进入 APP_ID 字段。这是一件那么它不会是Android的人真正完全相关的离子。这是一个小问题。如果我看了看源$ C ​​$ C更早。我现在已经知道了。但不管怎么说四天解决,最后它的工作。
如果anythings没有在注释工作后,我会帮助你。

Okay, guys here it goes, after my final showdown I was the winner. I figured out finally. I had not entered the app_id field. It was something related completely to ionic so it wouldn't be true for android people. It was a small issue. Had I looked at the source code earlier. I would have known it by now. But anyways four days to solve and finally it's working. If anythings is not working post in the comments I'll help you out.

因此​​,流动是这样的。

So the flow goes like this.

ionic config set dev_push false

ionic push --google-api-key AIzaSyB9L****************5if1m5k5JOVMw

ionic config set gcm_key 148*****5078

ionic config set app_id (some_alphanumeric_value found on ionic.io and is availble after you have done ionic io init)

这篇关于为什么我无法通过离子框架接收Android上的推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆