React-native-push-notification: OnNotification not getting called

Created on 5 Feb 2020  Â·  13Comments  Â·  Source: zo0r/react-native-push-notification

Hello,
I am working with scheduled local notifications and getting all the notifications in all conditions but I am in no way able to get the onNotification called when app is in foreground or background when a notification is tapped. But it is working fine when app is killed and then we tap on the notification. Also if the app is killed and we tap on one of the notifications sent through app, all the notifications get cleared. Can anyone give me an working example where all these problems don't arise? Basically I want to tap on a notification be the app foreground or background or killed and I want to navigate to a screen. Thanks.

Most helpful comment

Add this to AndroidManifest.xml

android:name=".MainActivity"
android:launchMode="singleTask"

This worked for me.

All 13 comments

Same issue, i am using "react-native-push-notification": "^3.1.9". I am using localNotification. Notification appears but onNotification function isn't invoking.

Same issue, i am using "react-native-push-notification": "^3.1.9". I am using localNotification. Notification appears but onNotification function isn't invoking.

Am using the same version . But I have also downgraded it to 3.1.2/3.1.1 where few said it was working. But it's not. Am stuck on these since the last two days .

same issue here onNotification is not getting called on click of notification

Same here

Same, notification appears but onNotification method is not called. Any workaround?

Add this to AndroidManifest.xml

android:name=".MainActivity"
android:launchMode="singleTask"

This worked for me.

Add this to AndroidManifest.xml

android:name=".MainActivity"
android:launchMode="singleTask"

This worked for me.

On Android works for me too, is the iOS that isn't working

Thanks well try this

On Fri, Feb 14, 2020 at 1:05 PM Arslan Sajid notifications@github.com
wrote:

Add this to AndroidManifest.xml

android:name=".MainActivity"
android:launchMode="singleTask"

This worked for me.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/zo0r/react-native-push-notification/issues/1304?email_source=notifications&email_token=ALW66TAGHO2LV3I5PFM4QY3RCZCS5A5CNFSM4KQN47MKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELX3OUI#issuecomment-586135377,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ALW66TEJIXI2H2LLD3YHZ63RCZCS5ANCNFSM4KQN47MA
.

on iOS as it uses @react-native-community/push-notification-ios you must add in your Xcode project in the appdelelgate

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
  [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];

  completionHandler(UIBackgroundFetchResultNoData);
}

@nicpro85 , I have same issue, and I added this part in AppDelegate.m

completionHandler(UIBackgroundFetchResultNoData);

I added a more line to complete as your suggestion: completionHandler(UIBackgroundFetchResultNoData);. It is working now. The event is fired when receiving notification in foreground mode. Thanks

It's not working for me in iOS 13.4 device completionHandler(UIBackgroundFetchResultNoData);. only works in background. any idea?

"react": "16.9.0",
"react-native": "0.61.5",
"react-native-push-notification": "^3.1.9",
"@react-native-community/push-notification-ios": "^1.0.7",

Add this to AndroidManifest.xml

android:name=".MainActivity"
android:launchMode="singleTask"

This worked for me.

This also worked for me.

Was this page helpful?
0 / 5 - 0 ratings