-
Notifications
You must be signed in to change notification settings - Fork 281
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
Push and local notifications not working when app is in foreground #129
Comments
Am also facing this issue. Have followed the docs and triple checked everything. Am able to receive push notifications when app is closed or app is in background. Not able to receive push notifications or local notification when app is on foreground. Have tried all sorts of work around but nothing works. Appreciate if someone has some insights on this. Thanks! |
I have the same situation. Local notifications don't appear when the app is in foreground. Will be so grateful to get some help on this. Thanks! |
Hey guys! I found the issue in my code, partially thanks to the issue #63 Let me share with you final results with working code: What I added to
In
And at the end of the file
Please let me know if it helps you! Now everything works on my side. I have installed this package + package from wix just to choose |
@natasha08n thanks for your help but I've implemented the same methods as you can see in the issue details and it's not working for me. |
Did you add some lines to AppDelegate.h file? |
`#import <UserNotifications/UNUserNotificationCenter.h> @interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate> @end` @natasha08n this is my AppDelegate.h file |
Same here, but only the second time i open the app. (When i kill the app and re-open) |
Did anyone manage to fix this ? |
In my case foreground notifications doesn't work due to data i passed to |
Summary
After updating the library to 1.2, unable to get push or local notifications when app is in the foreground. It's working fine when app is inactive or in background. I think there is some change needed in 'AppDelegate.m' file, method name 'willPresentNotification' is not getting triggered when app receives any push/local notification. I've done some NSLogs in the same method but nothing gets printed on the console.
For local notifications, i've implemented 'PushNotificationIOS.presentLocalNotification' but it's also not working.
Environment info
Library version: 1.2.0
AppDelegate.m file
//Added these lines in didFinishLaunchingWithOptions method
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
//--------------------
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}
// Required to register for notifications
{
[RNCPushNotificationIOS didRegisterUserNotificationSettings:notificationSettings];
}
// Required for the register event.
{
[RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
// Required for the notification event. You must call the completion handler after handling the remote notification.
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
[RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
// Required for the registrationError event.
{
[RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error];
}
// IOS 4-10 Required for the localNotification event.
{
[RNCPushNotificationIOS didReceiveLocalNotification:notification];
}
// IOS 10+ Required for localNotification event
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler
{
[RNCPushNotificationIOS didReceiveNotificationResponse:response];
completionHandler();
}
On React side for local notifications
if (Platform.OS === 'ios') {
PushNotificationIOS.presentLocalNotification({
alertBody: message,
alertTitle: title,
userInfo: data
});
}
else {
PushNotification.localNotification({
/* Android Only Properties */
ticker: "My Notification Ticker", // (optional)
autoCancel: true, // (optional) default: true
.......
)};
}
Thanks in advance...
The text was updated successfully, but these errors were encountered: