ios
ios copied to clipboard
Push Notification call back not get when app is in background
when app is in the background we get the notification but do not get that callback for any action we can do on that callback
@siddharthpvi did you find a solution?
+1 this is happening to us as well. We are trying to run some code whenever a notification is received while the app is in the background / phone is locked. Have gone through troubleshoot page, but there doesn't seem to be anything around the callback not being fired off.
Not
In order to wake the app when a notification is received, since iOS 13, you need to add the "content-available":1,
value to the notification's aps
field. Without it, your app will not receive any of the event handlers when it is in the background and a notification is received.
So far I have only been able to get this to work on a real device using notifications sent through node-apn
. .apns
files sent to the simulator, even with the content-available field, do not seem to work no matter what listener I implement (e.g. {"Simulator Target Bundle": "my.app.id","aps":{"sound":"default","alert":"Test","badge":1,"content-available":1}}
).
@MartijnHols ... This was added and working fine... But after upgrading to react native version 0.66 ... It dont trigger notification on background.
I have this issue too, can anyone help?? react-native version: 0.63.4
+1 this is happening to us as well. We are trying to run some code whenever a notification is received while the app is in the background / phone is locked. Have gone through troubleshoot page, but there doesn't seem to be anything around the callback not being fired off.
Have you managed to solve this?
@wlek777 ... i ended up using @notifee/react-native it was a better option.. So, I use it for only Local notifications... pass the Remote notification data to it. It would be very helpful and currently, they made the library free.
@Joshmatjjen I cannt even get the remote notification data when killed state, this worked fine when app state in active/background (without swipe off the app)
@wlek777 ... Is it IOS or Both Android And IOS?
@Joshmatjjen IOS only
I used react-native-push-notification & @react-native-community/push-notification-ios
react-native-push-notification , was used to configure the remote notification. like this
// Root component.. ie App.js
import PushNotificationIOS from '@react-native-community/push-notification-ios';
import PushNotification, { Importance } from 'react-native-push-notification';
PushNotification.configure({
// Called when Token is generated.
onRegister: function (token) {
console.log('TOKEN:', token);
// Register ur remote notificaiton to listen to
},
// Called when a remote or local notification is opened or received.
onNotification: function (notification) {
console.log('NOTIFICATION:----REMOTE', notification);
console.log(notification.data.type);
);
PushNotification.cancelAllLocalNotifications();
console.log('NO Push', notification);
}
// .then((url) => console.log('Hello uRl', url))
// .catch((err) => console.log(err));
// Do something with the notification.
// Required on iOS only (see fetchCompletionHandler docs: https://reactnative.dev/docs/pushnotificationios)
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
// (optional) Called when Registered Action is pressed and invokeApp is false, if true onNotification will be called (Android)
onAction: function (notification) {
console.log('ACTION:', notification.action);
console.log('NOTIFICATIONS:', notification);
// PushNotification.getChannels(function (channel_ids) {
// console.log('Channel ID', channel_ids); // ['channel_id_1']
// });
// process the action
},
// (optional) Called when the user fails to register for remote notifications. Typically occurs when APNS is having issues, or the device is a simulator. (iOS)
onRegistrationError: function (err) {
console.log('THis is the error registering notification', err);
console.error(err.message, err);
},
// 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
* - if you are not using remote notification or do not have Firebase installed, use this:
* requestPermissions: Platform.OS === 'ios'
*/
requestPermissions: true,
// ANDROID: GCM or FCM Sender ID
senderID: '112233333333',
});
Same issue, the callback is getting triggered when app is in foreground, but it does not get triggered at all when the app is closed or in the background.
Has anyone found a work around?
@DarshanDodal @MartijnHols @wlek777 @Saad-Bashar @Joshmatjjen have you guys found solution for this ?
@ambessh .. Not yet bro.... Does any one know of a library that can always listen to function on Background...
@ambessh @DarshanDodal @MartijnHols @Saad-Bashar. react-native-push-notification is no longer maintained ....Please Switch to this library.... Thank me later
@Joshmatjjen Thank you so much!!.