onNotification not being called when app was killed on iOS
See original GitHub issueBug
I am sending local notifications using react-native-background-fetch
. This works good. When the user clicks on a notification I redirect him to a certain screen. This always works in Android.
For iOS it is working when the app is in foreground or background. When the app was killed and the user clicks on a notification, the app launches but the onNotification
handler is not being called.
I call PushNotification.configure
from index.js
, so timing should not be the issue.
I followed the fix here to get onNotification
to work in foreground and background.
Environment info
react-native info
output:
info
React Native Environment Info:
System:
OS: macOS 10.15.5
CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
Memory: 4.00 GB / 32.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 10.16.3 - ~/.nvm/versions/node/v10.16.3/bin/node
npm: 6.13.6 - ~/.nvm/versions/node/v10.16.3/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK:
API Levels: 23, 26, 27, 28, 29
Build Tools: 23.0.1, 26.0.3, 27.0.3, 28.0.3, 29.0.3
System Images: android-29 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom_64
IDEs:
Xcode: 11.5/11E608c - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.5 => 0.59.5
npmGlobalPackages:
react-native-cli: 2.0.1
Library version: the development branch of this repo for the latest Android notification action fixes
Steps To Reproduce
- Configure the
onNotification
handler inindex.js
- Send a push notification while the app is killed
- Check if the
onNotification
handler was called when the notification is clicked
Describe what you expected to happen:
onNotification
should be called when coming from Foreground/Background or when the app was killed
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:49
was this ever resolved? having this issue when I send a silent notification, the app wakes up from a kill state but doesn’t call onNotification. This works well in android
Hi Friends, i have found solution. Please check below methods.
Add this code in below file. AppDelegate.m
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { …
if (launchOptions != nil) { NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if (userInfo != nil) { [self performSelector:@selector(callNotification:) withObject: userInfo afterDelay:10]; } }
… }
create new file methods in same class…
-(void) callNotification: (NSDictionary*) userInfo { [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo]; }
Modify below File from framework RNCPushNotificationIOS.m
Update above line on this methods.
Now Check, you will data on onNotification method…
Hope this work for you…