Meteor-Community-Packages / raix-push

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

Notification is being sent but not received #365

Closed saikatharryc closed 5 years ago

saikatharryc commented 5 years ago

Hi, here is the debug console:

I20190314-12:09:13.131(5.5)? sendGCM [ 'xxxxxx:xxxxxx-QLsA8a6P9kWo6lzejmDWZ2eKNI2kgmPPUuuQtJ4AE6kXa4Ab4lJiHnLmLLk_LJ6qR6rfheSS0pSaZepOauvluV1q92jrP-txc' ] { _id: 'T7BBqr5PzD5YBsq8g',
I20190314-12:09:13.131(5.5)?   createdAt: 2019-03-14T06:39:07.120Z,
I20190314-12:09:13.132(5.5)?   createdBy: '<SERVER>',
I20190314-12:09:13.132(5.5)?   from: 'push',
I20190314-12:09:13.132(5.5)?   title: 'new notification',
I20190314-12:09:13.133(5.5)?   text: 'you have a new notification',
I20190314-12:09:13.133(5.5)?   badge: 5,
I20190314-12:09:13.133(5.5)?   sound: 'default',
I20190314-12:09:13.134(5.5)?   notId: 1552545547,
I20190314-12:09:13.134(5.5)?   apn: { sound: 'default' },
I20190314-12:09:13.134(5.5)?   query: {},
I20190314-12:09:13.135(5.5)?   contentAvailable: 1,
I20190314-12:09:13.135(5.5)?   sent: false,
I20190314-12:09:13.135(5.5)?   sending: 0 }
I20190314-12:09:13.136(5.5)? Create GCM Sender using "xxxxx:xxxxxxxxxx"
I20190314-12:09:13.136(5.5)? A:Send message to: xxxx:xxxxx-QLsA8a6P9kWo6lzejmDWZ2eKNI2kgmPPUuuQtJ4AE6kXa4Ab4lJiHnLmLLk_LJ6qR6rfheSS0pSaZepOauvluV1q92jrP-txc
I20190314-12:09:13.136(5.5)? send to token { gcm: 'e72SWDo2dTI:zxxxxx-6vdGhBWi9gfCPadw-x0lWaIaHznJQmhmTfTgRYRhK4AYQTt9JN8B4ZPwvfusrgxVE165' }
I20190314-12:09:13.137(5.5)? sendGCM [ 'xxxx:xxxxx-6vdGhBWi9gfCPadw-x0lWaIaHznJQmhmTfTgRYRhK4AYQTt9JN8B4ZPwvfusrgxVE165' ] { _id: 'T7BBqr5PzD5YBsq8g',
I20190314-12:09:13.137(5.5)?   createdAt: 2019-03-14T06:39:07.120Z,
I20190314-12:09:13.137(5.5)?   createdBy: '<SERVER>',
I20190314-12:09:13.137(5.5)?   from: 'push',
I20190314-12:09:13.138(5.5)?   title: 'new notification',
I20190314-12:09:13.138(5.5)?   text: 'you have a new notification',
I20190314-12:09:13.138(5.5)?   badge: 5,
I20190314-12:09:13.139(5.5)?   sound: 'default',
I20190314-12:09:13.139(5.5)?   notId: 1552545547,
I20190314-12:09:13.139(5.5)?   apn: { sound: 'default' },
I20190314-12:09:13.140(5.5)?   query: {},
I20190314-12:09:13.140(5.5)?   contentAvailable: 1,
I20190314-12:09:13.140(5.5)?   sent: false,
I20190314-12:09:13.141(5.5)?   sending: 0 }
I20190314-12:09:13.141(5.5)? Create GCM Sender using "xxxxx:APA91bED_7kx4YlbH_O1EztfUuBXPB1HNI3zQGz8sRjf9me8TGFpiGsRYYuGhB2qGEA96QkD_5akPeNMH8qk_JROJl2y8eymbkDSfeFFzdB6Dtv3SD9eHVwhbBYbMY8Fw7G2ffD7fapS"
I20190314-12:09:13.141(5.5)? A:Send message to: xxxx:xxxx-6vdGhBWi9gfCPadw-x0lWaIaHznJQmhmTfTgRYRhK4AYQTt9JN8B4ZPwvfusrgxVE165
I20190314-12:09:13.142(5.5)? Push: Sent message "new notification" to 0 ios apps 5 android apps
I20190314-12:09:13.397(5.5)? Push, GUIDE: The "Push.appCollection" - No APN clients have registred on the server yet...
I20190314-12:09:14.749(5.5)? 03-14 12:09:13.312  6977  6977 I chromium: [INFO:CONSOLE(91)] "Push.Notification:", source: http://localhost:12696/__cordova/packages/raix_push.js?hash=2f722db8f96f131982fbe5f2f43ae0cedfc0d717 (91)
I20190314-12:09:14.750(5.5)? 03-14 12:09:13.312  6977  6977 I chromium: [INFO:CONSOLE(91)] "Push.SettingBadge:", source: http://localhost:12696/__cordova/packages/raix_push.js?hash=2f722db8f96f131982fbe5f2f43ae0cedfc0d717 (91)
I20190314-12:09:14.751(5.5)? 03-14 12:09:13.312  6977  6977 I chromium: [INFO:CONSOLE(91)] "Push.Message: Got message while app is open:", source: http://localhost:12696/__cordova/packages/raix_push.js?hash=2f722db8f96f131982fbe5f2f43ae0cedfc0d717 (91)
I20190314-12:09:14.807(5.5)? ANDROID: Result of sender: {"multicast_id":6013352723810098000,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1552545554539103%afacf3a10034af1a"}]}

i can see notification is being sent and in listner function also it coming as expected. now the gcm token its actually saving in DB i have tried using that with the fcm server key in apns-gcm.bryantan.info, and its working there too.

but in this case its seems sending but not received any push notification.

cordova plugin used:

cordova-android-support-gradle-release@2.0.1
cordova-plugin-device@1.1.5
cordova-plugin-geolocation@4.0.1
cordova-plugin-inappbrowser@3.0.0
cordova-plugin-meteor-webapp@1.4.1
cordova-plugin-web-share@1.2.0
de.appplant.cordova.plugin.local-notification@0.8.5
phonegap-plugin-push@1.5.2

METEOR@1.8.0.1

here is how i'm triggering send:

 //start here
    const notId = Math.round(new Date().getTime() / 1000);

    const title = "new notification";
    const text = "you have a new notification";
    //custom info
    const payload = { info: "test", url: "http://www.google.fr" };
    //number
    const query ={}
    const badge = 5;

    const payloadStringify = {};
    payloadStringify.custom_key1 = JSON.stringify(payload);

    Push.send({
        from: "push",
        title,
        text,
        // payload: payloadStringify, // All payload values must be strings if sending using FCM
        sound: "default",
        query,
        badge,
        apn: {
            sound: "default"
        },
        contentAvailable: 1,
        androidChannel: "PushPluginChannel",
        notId
    });

even on send i'm getting a alert as well, as i did in /client/main.jsx

 Push.addListener("message", function(notification) {
        window.confirm(notification.message, "notifications", [
            "Voir",
            "fermer"
        ]);
    });

Note: i'm testing in android 7.0 for a note, i can see there is collection named _raix_push_notifications but it has no doc.

shivang007 commented 5 years ago

Update your phonegap-plugin-push version to 1.9.0 and cordova-plugin-device to 1.1.6

I am making following assumptions:

  1. You are allowing users to send notification in your server's config
    Push.allow({
     send: (userId, notification) => {
       return true;
     }
    });
  2. On client side you have this config on Meteor.startup
    Meteor.startup(() => {
    Push.Configure({
    android: {
      senderID: YOUR_SENDER_ID,
      alert: true,
      badge: true,
      sound: YOUR_SOUND,
      vibrate: true,
      clearNotifications: true,
      icon: 'notif',
      iconColor: '#33752e'
    },
    ios: {
      alert: true,
      badge: true,
      sound: true,
      clearBadge: true,
      categories: categories
    }
    });
    });
  3. You have Meteor users.

Now Signin using one of the user and quit the app.

Send this simple notification

Push.send({
  from: 'push',
  title: 'Test Notification',
  text: 'Test Message.',
  badge: 1,
  notId: 123456,
  query: {},
  apn: {
    sound: "YOUR_SOUND"
  },
  gcm: {
    sound: 'YOUR_SOUND'
  },
  androidChannel: "PushPluginChannel"
});

The empty query will send notification to all meteor users.

saikatharryc commented 5 years ago

hi, @shivang007 i have tried the same, and confirming i have folowwed this procedure only, but happens same issue, its saying notifiation sent, but no notifidation came, and also note that in app only after loging in, i have placed this:

 //start here
    const notId = Math.round(new Date().getTime() / 1000);

    const title = "new notification";
    const text = "you have a new notification";
    //custom info
    const payload = { info: "test", url: "http://www.google.fr" };
    //number
    const query ={}
    const badge = 5;

    const payloadStringify = {};
    payloadStringify.custom_key1 = JSON.stringify(payload);

    Push.send({
        from: "push",
        title,
        text,
        // payload: payloadStringify, // All payload values must be strings if sending using FCM
        sound: "default",
        query,
        badge,
        apn: {
            sound: "default"
        },
        contentAvailable: 1,
        androidChannel: "PushPluginChannel",
        notId
    });

behind a button press on server side.

here is the code from Meteor.startup() . in server/main.js:

 const serviceAccountJson = JSON.parse(
            Assets.getText("FirebaseAdminSdkServiceAccountKey.json")
        );

        Push.Configure({
            fcm: {
                serviceAccountJson: serviceAccountJson
            },
            gcm:{
                projectNumber: xxx,
                apiKey:"xxx"
            },
            production: true,
            sound: true,
            badge: true,
            alert: true,
            vibrate: true,
            appName: "main"
        });
        Push.allow({
            send: (userId, notification) => {
                // allow all users to send notifications
                return true;
            }
        });
        Push.addListener("error", err => {
            console.error("error on push: " + err); // no error is received here
        });
shivang007 commented 5 years ago

So you are getting the platform alert? If you are getting it then that means notification is working and since your app is open, you will receive alert instead of notification.

Also, in your server/main.js put the code related to Push inside Meteor.startup()

saikatharryc commented 5 years ago

is there anyway to receive push notification when app is open? how do i send in that case?

shivang007 commented 5 years ago

If your app is open then the notification will be handled internally (Alert in this case), as there is no need to send a push to the user (as done by normal apps, amazon and such).

For testing, instead of triggering it from client, keep the code on server, which will run as soon as your server starts.

Anyways in real life scenario, you will have a cron/specific action which will trigger your server to send notification to that particular user.

saikatharryc commented 5 years ago

@shivang007 isnt there any way? in case we want to show push notification irredpective of the app state open/close ? if anything needs to be done manually to make it happen ?

shivang007 commented 5 years ago

For that I usually keep a meteor method which I trigger from web-browser's console.

Meteor.methods({
  testNotificationMethod: function(recipients) {
    var notificationPayload = {
      from: 'push',
      title: 'Test Notification',
      text: 'Test Message',
      badge: 1,
      notId: 123456,
      query: {
        userId: { $in: recipients }
      },
      apn: {
        sound: "YOUR_SOUND"
      },
      gcm: {
        sound: 'YOUR_SOUND'
      }
    };

    Push.send(notificationPayload);
  }
});

From your console, trigger

Meteor.call('testNotificationMethod', ['user_id']);
saikatharryc commented 5 years ago

yeah, so in my case, i kept that push.send() inside a method only, and i'm calling that onclick of some button in frontend. now when i click, i get only that alert. which is defined in the client/main.jsx . its not coming in the notification drawer.

shivang007 commented 5 years ago

This wont do anything if the user's app is open during the time you sent this. So for that you have to handle it on your client's

Push.addListener('alert', function(notification) {})

I used the sweetalert2 (https://sweetalert2.github.io/) for that.

shivang007 commented 5 years ago

now when i click, i get only that alert. which is defined in the client/main.jsx . its not coming in the notification drawer.

You can not get notification in your drawer if your app is open. There is just no point of it ux wise.

saikatharryc commented 5 years ago

@shivang007 thanks for helping me out.thanks a lot. the only thing it took me 2-3 days, lack of understanding which version of packages to use, and few confusion.

it will be great. if someone can just update the docs . although i havent tested with IOS yet, i'm closing this issue by assuming it will work as expected in production and IOS too. :p ;)

shivang007 commented 5 years ago

@saikatharryc No problem! Yes the docs have become messy since past few versions, I will make sure to change it as soon as I get some free time.

As for your sending the notification even when the app is running, you can pursue this https://forums.meteor.com/t/local-notifications/37060

The scenario would be like a persistent notification such as when you use whatsApp Web and the WhatsApp Web is currently active stays in your notification tray all the time.

saikatharryc commented 5 years ago

@shivang007 noted that, and can you also help me where to place the icon or load the icon for ios notifications? i got answer for the android from here https://github.com/raix/push/pull/359#issuecomment-459061452

shivang007 commented 5 years ago

@saikatharryc you need to put your icons in mobile-config.js

App.icons({
  "android_mdpi": "resources/android/icon/mipmap-mdpi/ic-launcher.png", // 48x48
  "android_hdpi": "resources/android/icon/mipmap-hdpi/ic-launcher.png", // 72x72
  "android_xhdpi": "resources/android/icon/mipmap-xhdpi/ic-launcher.png", // 96x96
  "android_xxhdpi": "resources/android/icon/mipmap-xxhdpi/ic-launcher.png", // 144x144
  "android_xxxhdpi": "resources/android/icon/mipmap-xxxhdpi/ic-launcher.png", // 192x192
  "iphone_2x": "resources/ios/AppIcon.appiconset/Icon-App-60x60@2x.png",
  "iphone_3x": "resources/ios/AppIcon.appiconset/Icon-App-60x60@3x.png",
  "ipad_app_legacy": "resources/ios/AppIcon.appiconset/Icon-App-72x72@1x.png",
  "ipad_app_legacy_2x": "resources/ios/AppIcon.appiconset/Icon-App-72x72@2x.png",
  "ipad": "resources/ios/AppIcon.appiconset/Icon-App-76x76@1x.png",
  "ipad_2x": "resources/ios/AppIcon.appiconset/Icon-App-76x76@2x.png",
  "ipad_pro": "resources/ios/AppIcon.appiconset/Icon-App-167x167@1x.png",
  "ios_settings_2x": "resources/ios/AppIcon.appiconset/Icon-App-29x29@2x.png",
  "ios_settings_3x": "resources/ios/AppIcon.appiconset/Icon-App-29x29@3x.png",
  "ios_notification_2x": "resources/ios/AppIcon.appiconset/Icon-App-20x20@2x.png",
  "ios_notification_3x": "resources/ios/AppIcon.appiconset/Icon-App-20x20@3x.png",
  "ios_spotlight_2x": "resources/ios/AppIcon.appiconset/Icon-App-40x40@2x.png",
  "ios_spotlight_3x": "resources/ios/AppIcon.appiconset/Icon-App-40x40@3x.png",
  "ios_settings": "resources/ios/AppIcon.appiconset/Icon-App-29x29@1x.png",
  "ios_spotlight": "resources/ios/AppIcon.appiconset/Icon-App-40x40@1x.png",
  "app_store": "resources/ios/iTunesArtwork@2x.png"
});