Meteor-Community-Packages / raix-push

DEPRECATED: Push notifications for cordova (ios, android) browser (Chrome, Safari, Firefox)
https://atmospherejs.com/raix/push
MIT License
513 stars 197 forks source link

[v3.0.3-rc.7][v3.0.2] Android FCM not working #259

Open v3rron opened 7 years ago

v3rron commented 7 years ago

Since we migrated from Google GCM to FCM on Firebase and upgraded the package to v3.0.3-rc.7, I can't get Android notifications to work. Here's my settings.json

{
  "public": {
    "environment": "staging",
    "pushClient": {
      "android": {
        "senderID": "XXXXXXXXXX",
        "alert": true,
        "badge": true,
        "sound": true,
        "vibrate": true,
        "clearNotifications": true
      },
      "ios": {
        "alert": true,
        "badge": true,
        "sound": true
      }
    }
  },
  "pushServer": {
    "apn": {
      "passphrase": "XXXXXXX",
      "gateway": "gateway.push.apple.com",
      "production": true
    },
    "gcm": {
      "apiKey": "XXXXXXXXX",
      "projectNumber": "XXXXXXXXX"
    },
    "production": true,
    "sound": true,
    "badge": true,
    "alert": true,
    "vibrate": true
  },
  "pushServerKeys": {
    "cert": "apnCert.pem",
    "key": "apnKey.pem"
  }
}

This is my server/push.js

// Configure Push Notifications - raix:push
let pushConfigs = Meteor.settings.pushServer;
pushConfigs.apn.keyData = Assets.getText(Meteor.settings.pushServerKeys.key);
pushConfigs.apn.certData = Assets.getText(Meteor.settings.pushServerKeys.cert);

Push.Configure(pushConfigs);

Push.addListener('error', (error) => {
  throw new Meteor.Error(error);
});

if (Meteor.settings.public.environment !== 'production') {
  Push.debug = true; // Add verbosity
}

And this is my client/push.js:

Push.Configure(Meteor.settings.public.pushClient);

iOS Notifications are working, but that's the log I get for Android notifications:

Push: Send message "Someone is interested!" via query { userId: 'ahPcp7cmLnAa42xW3' }
send to token { gcm: 'JHG84DDCJ61fcLscyJAsbua368asjbdsvdhajsv276bjahvd_AhfJASVHGsghav-BjJxMhF2dc2LD6zzwYfJxwGcahAHGSVshvA6l_HvE9gwItWuYi-t4h4caJv0t5YJ1-iSHGF_5g' }
sendGCM [ 'NGS71bF1ZlRCJ61fcLscyZD2N1sYXzsX7_WwLCzc9eNnH0T9WEbo9nap_NnAqLqeDSF32D-BjJxMhSfshav387ydh6zzwYfJxwGcpFWmxqdxA6l_ds465jfSG3wsHGSVj-t4h4caJv0t5YJ1-iWIb_6a' ] { _id: 'j3gfQtA69ggahnfC',
  createdAt: Thu Oct 06 2016 00:01:00 GMT+0000 (UTC),
  createdBy: '<SERVER>',
  from: 'Post',
  title: 'Someone is interested!',
  text: 'Carl is interested in attending your event.',
  badge: 1,
  query: { userId: 'hsja7g54anAa42g4H' },
  sent: false,
  sending: 0 }
Create GCM Sender using "kuBSsJH789OX6EfV03Ka0D9wbHhw7vbaj37JHSb36"
A:Send message to: NGS71bF1ZlRCJ61fcLscyZD2N1sYXzsX7_WwLCzc9eNnH0T9WEbo9nap_NnAqLqeDSF32D-BjJxMhSfshav387ydh6zzwYfJxwGcpFWmxqdxA6l_ds465jfSG3wsHGSVj-t4h4caJv0t5YJ1-iWIb_6a
Push: Sent message "Someone is interested!" to 0 ios apps 1 android apps
ANDROID ERROR: result of sender: undefined

PS: all the keys and sensitive info was modified before posting. PPS: tried to downgrade back to 3.0.2 with old GCM key, but still can't get Android notifications to work, even though it's currently working with our production code. Hers's the error message:

Unauthorized
ANDROID: Result of sender is null
markodvornik commented 7 years ago

It looks like a FCM API credentials problem. I had the same error with GCM, migrating to [v3.0.3-rc.7] and FCM fixed it (using Server key (legacy token) and Sender ID).

I followed this ANDROID GUIDE.

v3rron commented 7 years ago

@macakraca I'm doing the same here. Migrated to v3.0.3-rc.7. Migrated Google to Firebase, regenerated Server Key, copied that key to gcm.apiKey in the config. Did you use raix:push-update or raix:setuser methods by any chance?

markodvornik commented 7 years ago

@v3rron no.

server:

Meteor.methods({
    serverNotification: function(text, title, subscribed_users) {
        var badge = 1
        var push = Push.send({
            from: 'push',
            title: title,
            text: text,
            badge: badge
            gcm: {
                style: 'inbox',
                summaryText: 'Unread: %n%'
            },
            apn: {
                sound: 'default'
            },
            payload: {
                title: title,
                text: text
            },
            query: {
                userId: {$in: subscribed_users}
            },
            notId: Math.round(new Date().getTime()/1000)
        });
    }
});

client:

if (Meteor.isCordova) {
    // push
    Push.Configure({
        android: {
            senderID: ***,
            alert: true,
            badge: true,
            sound: true,
            vibrate: true,
            clearNotifications: true
            // icon: '',
            // iconColor: ''
        },
        ios: {
            alert: true,
            badge: true,
            sound: true
        }
    });

    Push.setBadge(0);
}
rajpa commented 7 years ago

hi @v3rron how did you get to see the log generated by Push? Can you pls help.

Cheers rajpa

rajpa commented 7 years ago

My app is receiving FCM messages from the Firebase console but not from my server.

v3rron commented 7 years ago

@rajpa we're using mup for deployment, so in our case it's:

mup logs