-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Added method getScheduledLocalNotifications() #1466
Conversation
Fixing typo in pull request submission documentation.
If everything is a-okay, I'll write some documentation for this. Currently notifications are returned this way, not sure if we should trim android part or not: Android:
iOS:
|
Hi @lukebars Not all parameters, but we can try at least shared params. Something like [{
"id": "12345",
"date": new Date(),
"message": "Body Message",
"number": 0,
"sound": "default",
"raw": {
// full output iOS:
"alertAction": null,
"alertBody": "Body Message",
"applicationIconBadgeNumber": 0,
"category": null,
"fireDate": "2020-06-05T15:34:03.327+03:00",
"remote": false,
"soundName": "default",
"userInfo": {
"id": "12345",
}
// full output Android:
"actions": null,
"autoCancel": false,
"bigText": null,
"color": null,
"fireDate": 1591359819185,
"group": null,
"id": "12345",
"largeIcon": "ic_notif",
"message": "Body Message",
"number": null,
"ongoing": false,
"playSound": false,
"repeatTime": 0,
"repeatType": null,
"smallIcon": "ic_notif",
"sound": null,
"subText": null,
"tag": null,
"ticker": null,
"title": "Notification",
"userInteraction": false,
"vibrate": false,
"vibration": 0
}
}] |
@Dallas62 I've decided that the best solution would be to keep it as clean and unified as possible, and staying true to RNCPushNotificationsIOS structure on both platforms. This would be the structure I've prepared to return on both platforms rn: "alertAction": null,
"alertBody": "Body text",
"alertTitle": "Notification title",
"applicationIconBadgeNumber": null,
"fireDate": "2020-06-08T13:01:52.542+03:00",
"id": 1793677506,
"remote": false,
"repeatInterval": null,
"soundName": null, I've raised a PR in react-native-community that will return |
…iOS return object
Nice for the iOS PR ! 😉
This is not the name used in the initial method PushNotification.localNotificationSchedule. This might lead to confusion. This changes can be made in the JS part. |
Sounds good. I'll reflect the changes |
… in unix timestamp as before
@Dallas62 iOS changes have been merged and released to I've also updated the code for soundName: 'default',
repeatInterval: 0,
id: 5,
date: 2020-06-08T12:07:30.039Z, // Date instance (new Date(fireDate))
number: 0,
message: 'Notif message',
title: 'Notif title', |
Thanks for all these changes, I will find time the week to review and merge it 😉 |
@Dallas62 thanks for your collaboration! I've bumped the RNCPushNotificationIOS to |
return ({ | ||
soundName: notif.soundName, | ||
repeatInterval: notif.repeatInterval, | ||
id: notif.userInfo?.id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused about this line,
I totally agree iOS should have the notification ID, but by default, userInfo
is set to {}
.
Not sure if we need to set a default value on userInfo
(notificationId
?) or let this field empty when the developer doesn't set it in userInfo
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why it's optional chained here. It would result in undefined if it is not set. Currently we're using userInfo.id
for cancelling notifications by id, so it makes sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But setting the id as default when scheduling the notification would be an awesome feature IMHO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will look into it, thanks for the PR !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just added the commit here:
6bcc2a9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff! 🙏
when getScheduledLocalNotifications() will live for android in the master branch ? |
Hi, |
Great i am waiting for this change just moved to react-native-push-notification for local notification scheduling from react native firebase 6.0 |
@Dallas62 what about onNotification listener methods? Are you planning on releasing those? I'd be glad to help if you're facing any problems regarding that functionality |
Hi @lukebars, |
I might be wrong, but I think I've read that you were planning to add methods e.g. |
I didn't planned this kind of listener, but I was looking to implement actions for iOS. |
i have used the dev branch code of @lukebars the getScheduleLocalNotifications() function still not working in there for android i might be wrong but can you confirm it will work for android as well after releasing dev branch code at the end of the week ? |
@jaikantshikray Hmm.. It's working for me. I'm currently using it in production in one of our apps. Can you share some code of usage? |
@lukebars i have copied the java files from your dev branch and replacing the code of react-native-push-notifications java files you have created some new files as well and from your example file i have copied how you are using the getScheduledLocalNotifications() but unfortunately it is not working for me getScheduledLocalNotifications(callback) { MobxStore.getScheduledLocalNotifications((notifs)=>{ i have tried this as well MobxStore.getScheduledLocalNotifications().then(notifs => console.log(notifs)); but no response neither a crash |
Hi,
Or
|
@jaikantshikray can you share your thoughts on needed info? |
i need this data: { type: "schedule", data: item }, value in this response as well so i can utilize it and more if we can have date in unix format |
If you need unix time format just do this:
|
what about the data value ? |
Data value will not be retrieve in iOS, |
I think this is possible if you would care to submit a PR to RNCPushNotificationIOS. Until then, you need to figure out an another way. |
ok thank you waiting for this release i hope i can get that at the end of this week |
@Dallas62 is |
It's a bit tricky, I set the scheduled notification on There is some way to run tasks in background with iOS/Android, but using notifications for this is not a good thing I think. |
@Dallas62 I remember using RNFirebase v5 local notifications had such method If I understand correctly, current limitation is on iOS side? I could look into it and create a PR in the RNCPushNotificationIOS. Let me know what you think. EDIT: Nvm looks like onNotification works perfectly with local notifications on both platforms. I'm thinking about digging more into doing some research on creatin |
In iOS and Android, when notification are pressed every thing works fine. |
@Dallas62 I think onNotification method triggering on android notification displayed and not on iOS is very inconsistent. Maybe that should be separate method e.g. onNotificationDisplayed? Currently that gives me really hard time to implement |
@Dallas62 I tried to use on Android : PushNotification.getScheduledLocalNotifications((notifs) => console.log(notifs)) but it doesn't work. I'm on 5.1.0. |
Hi, Can you check that the version of the library is correctly installed ? Using yarn install instead of yarn upgrade, |
This method is really useful for organizing notifications, e.g. cancelling some of already scheduled ones. Solves #673
For iOS it uses already existing method
I've written a method for android which does the same.