-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
iOS - Notifications not showing up when app is in background #69
Comments
related to #17. Have a look at my last comment in the thread. Also, don't forget to add |
// fetch notifications in the background and foreground
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[RCTPushNotificationManager didReceiveRemoteNotification:notification];
completionHandler(UIBackgroundFetchResultNewData);
NSLog(@"Notification Body %@", notification);
} based on http://stackoverflow.com/a/36750318/2628278
|
Is there a way to give my RN app a few seconds to deal with the push notification? It needs to download some data basically and it looks like it's not been given enough time to do it. |
@npomfret Do you mean some time before the remote notification is shown or some time for it to complete the remote fetch task? |
It just needs time to do some work |
I think it is possible in iOS by enabling remote fetch for the notifications for which you want to do some work. You will need to set |
I've done all that stuff you've mentioned. The problem seems to be that the app gets suspended after a while and then killed by the OS. At this point if a push notification arrives (with content-available=1) it will try to launch the app, which it does. But it doesn't seem to give it long enough to get going. My app takes a few seconds to start, but i seems like the OS is only giving it a very short time to start. To make things more complicated I don't know how to get my app to tell my app delegate that it's finished processing the push notification and that it should call the completion handler. For the moment I'm just trying a Is there a more sensible way to do this? How do I get my RN app to tell me app delegate that it has processed the push notification?
|
The answer to this will be in react-native 0.38 I think |
Is it possible to display a local notification while the app is in the background? |
Yes its possible to display a local notification while the app is in the background. |
@hyperh do you still have this issue? if so, have you tried the latest release? if not, can we close it? |
@npomfret I am on RN 0.39.0, however, the app does not wake up if app closed by the user. On remote notification, this is what I see in the logs of the device. Notification received
The next logs are
The AppDelegate.m has the below code: // Required to register for notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[RCTPushNotificationManager didRegisterUserNotificationSettings:notificationSettings];
}
// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[RCTPushNotificationManager 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
{
[RCTPushNotificationManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
// Optionally implement this method over the previous to receive remote notifications. However
// implement the application:didReceiveRemoteNotification:fetchCompletionHandler: method instead of this one whenever possible.
// If your delegate implements both methods, the app object calls the `application:didReceiveRemoteNotification:fetchCompletionHandler:` method
// Either this method or `application:didReceiveRemoteNotification:fetchCompletionHandler:` is required in order to receive remote notifications.
//
// Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
[RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error];
}
// Required for the notification event.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification
{
NSLog(@"push-notification received: %@", notification);
[RCTPushNotificationManager didReceiveRemoteNotification:notification];
}
// Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[RCTPushNotificationManager didReceiveLocalNotification:notification];
} I am not sure if there is something to do with the completionHandler but I have also tried - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[RCTPushNotificationManager didReceiveRemoteNotification:notification];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
completionHandler(UIBackgroundFetchResultNewData);
});
} without any success! What I am trying to do is receive a silent remote notification, do my stuff and push a local notification. The app seems to receive the silent notification, however, the RN thread does not get called. Not a problem with this package, but something to do with the correct configuration of the PushNotifications Update I do not receive Remote silent notification when the device is locked or inactive (screen off), but if I wake the device and unlock, I see the messages received in the Guess, I will have to live with remote noisy notification for now. P.S. I am using one signal for remote notifications and have also installed react-native-onesignal package. Here is the gist of how the Notifications are configured within the app |
Yes that's expected behaviour and described in the trouble shooting guide. On iOS the app os will never relaunch the app if the user killed it. |
Can we close this issue? |
@npomfret I stopped working on the project which used this library. Feel free to close it if you like. |
I can trigger notifications when the app is in the foreground (i.e. they appear in the dropdown notifications area) but they don't seem to appear once the app is in the background.
The text was updated successfully, but these errors were encountered: