Created
December 16, 2018 10:44
-
-
Save LSViana/c2469ebd2bbc6e472177375d706f8621 to your computer and use it in GitHub Desktop.
react-native-push-notification in a foreground/background app snippet (put this inside the implementation of AppDelegate.m)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ 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]; | |
} | |
// Required for the registrationError event. | |
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error | |
{ | |
[RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error]; | |
} | |
// Required for the localNotification event. | |
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification | |
{ | |
[RCTPushNotificationManager didReceiveLocalNotification:notification]; | |
} | |
//Called when a notification is delivered to a foreground app. | |
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler | |
{ | |
NSLog(@"User Info : %@",notification.request.content.userInfo); | |
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment