-
Notifications
You must be signed in to change notification settings - Fork 293
Notification event listener is not called when app was killed #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@mathiasmoeller I've fixed that behavior by adding these lines to my app: async componentDidMount() {
const NotificationMessage = await PushNotificationIOS.getInitialNotification();
if (NotificationMessage) {
this._localNotificationHandler(NotificationMessage);
} else {
PushNotificationIOS.addEventListener(
'localNotification',
this._localNotificationHandler,
);
} |
Hey @MobileAppVault, thanks for the suggestion. |
I am confirming that PushNotificationIOS.getInitialNotification() returns always null after tapping the notification in the notification center (and of course while an app is killed). v. 1.3.0 |
here is my AppDelegate.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ...
// Define UNUserNotificationCenter
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
return YES;
} //Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}
// Required to register for notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[RNCPushNotificationIOS didRegisterUserNotificationSettings:notificationSettings];
}
// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
// Required for the notification event. You must call the completion handler after handling the remote notification.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
[RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
// Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
[RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error];
}
// IOS 10+ Required for localNotification event
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler
{
[RNCPushNotificationIOS didReceiveNotificationResponse:response];
completionHandler();
}
// IOS 4-10 Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[RNCPushNotificationIOS didReceiveLocalNotification:notification];
} It works for me an my changes are already in production. |
It seems, this issue is related to this one. You can close this issue. |
@rkostrab you linked this issue in your comment, was that on purpose? Because for me the issue still exists ;) |
@mathiasmoeller sorry, I've already fixed the link. Thanks |
@mathiasmoeller did you ever solve this? |
@mathiasmoeller is this still open or anyone found a fix for this? |
I stopped working on the project using react-native so I don't know if there is any progress here. Sorry :/ |
Is there any update on this issue? I am facing same issue. |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Summary
I am sending local push notifications (using react-native-background-fetch) to my app. I am using react-native-push-notifications for this which uses this repo under the hood.
I followed the issue here to get it working for notifications when the app is in foreground or background.
When the app is killed and I click on the notification, the app is being started but the handler registered via
PushNotificationIOS.addEventListener(type, handler);
is not called. Neither for the event typelocalNotification
nornotification
.The listeners are registered in
index.js
.Since background and foreground notifications are working I assume that the issue is in my
AppDelegate
configuration or a bug. Help is very welcome.Environment info
react-native info
output:Library version:
1.2.2
Steps to reproduce
Send push notification when the app is killed and check if the registered handler is called.
Reproducible sample code
My
AppDelegate.m
looks the following:My
AppDelegate.h
:Thanks a lot!
The text was updated successfully, but these errors were encountered: