Closed saikatharryc closed 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:
Push.allow({
send: (userId, notification) => {
return true;
}
});
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
}
});
});
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.
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
});
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()
is there anyway to receive push notification when app is open? how do i send in that case?
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.
@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 ?
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']);
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.
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.
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.
@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 ;)
@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.
@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
@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"
});
Hi, here is the debug console:
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:
METEOR@1.8.0.1
here is how i'm triggering send:
even on send i'm getting a alert as well, as i did in
/client/main.jsx
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.