Notice: 'NOTIFICATION:', { foreground: true,
userInteraction: false,
message: 'My Notification Message',
data: {},
badge: 0,
alert: 'My Notification Message',
sound: 'default' }
I get above values in the log but I am not getting any local notification in the emulator tray.
`
componentDidMount() {
PushNotification.configure({
// (optional) Called when Token is generated (iOS and Android)
onRegister: function(token) {
console.log( 'TOKEN:', token );
},
// (required) Called when a remote or local notification is opened or received
onNotification: function(notification) {
console.log( 'NOTIFICATION:', notification );
},
// ANDROID ONLY: GCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications)
senderID: "YOUR GCM SENDER ID",
// IOS ONLY (optional): default: all - Permissions to register.
permissions: {
alert: true,
badge: true,
sound: true
},
// Should the initial notification be popped automatically
// default: true
popInitialNotification: true,
/**
* (optional) default: true
* - Specified if permissions (ios) and token (android and ios) will requested or not,
* - if not, you must call PushNotificationsHandler.requestPermissions() later
*/
requestPermissions: true,
});
PushNotification.localNotification({
userInteraction: true,
alertAction: 'default',// (optional) default: view
/* iOS and Android properties */
title: "My Notification Title", // (optional, for iOS this is only used in apple watch, the title will be the app name on other iOS devices)
message: "My Notification Message", // (required)
actions: '["Yes", "No"]' // (Android only) See the doc for notification actions to know more
});
}
`
Hey bro, generally, when the app running in foreground, you won't see the notification. You can call the local schedule function and quick hide app to background, then you will see the notification.
schedule code:
PushNotification.localNotificationSchedule({
message: "My Schedule Notification Message", // (required)
number: 1,
date: new Date(Date.now() + (3 * 1000)) // in 3 secs
});
Is there any way to get the local notification showing on iOS when the app is in the foreground?
@JonoH You should implement it yourself in onNotification(), the simplest example is with alert() or toast (https://github.com/magicismight/react-native-root-toast).
For me they don't appear either on background having it scheduled for 3 seconds,
but i can hear the notification sound and see the console.log I have onNotification
I am also not getting notification in the background state.
I am able to receive it when it the app is not in the foreground. I've added a sample app for the same with is using expo.
https://github.com/leenasn/react-native-push-notification-sample
@opp100 it works like a gem thanks
those looking a solution to showing notification on iOS when the app is in the foreground.
this worked for me:
https://github.com/zo0r/react-native-push-notification/issues/275#issuecomment-333907923
remember to:
https://github.com/zo0r/react-native-push-notification/issues/275#issuecomment-334412456
For my case, i scheduled multiple notifications for next few days and next week. However changing the date time in device (earlier than scheduled) is not triggering the notification as expected when the time reaches the schedule.
Works fine if the notification is set few minutes or seconds further.
Any idea how to test schedule (days or weeks) local notifications properly?
Im testing on a ios simulator only.
remarks: even tried set 15minutes earlier than schedule and waited 15minutes but notification is not triggered.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.
Most helpful comment
Is there any way to get the local notification showing on iOS when the app is in the foreground?