diff --git a/ios/ZulipMobile/AppDelegate.h b/ios/ZulipMobile/AppDelegate.h index d86977f0770..43d1c2e998d 100644 --- a/ios/ZulipMobile/AppDelegate.h +++ b/ios/ZulipMobile/AppDelegate.h @@ -1,8 +1,9 @@ #import #import #import +#import -@interface AppDelegate : UIResponder +@interface AppDelegate : UIResponder @property (nonatomic, strong) UMModuleRegistryAdapter *moduleRegistryAdapter; @property (nonatomic, strong) UIWindow *window; diff --git a/ios/ZulipMobile/AppDelegate.m b/ios/ZulipMobile/AppDelegate.m index f75722e0596..569750ea4b6 100644 --- a/ios/ZulipMobile/AppDelegate.m +++ b/ios/ZulipMobile/AppDelegate.m @@ -57,6 +57,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( rootViewController.view = rootView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; + + // Define UNUserNotificationCenter + UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; + center.delegate = self; + return YES; } @@ -120,4 +125,16 @@ - (void)application:(UIApplication *)application didReceiveLocalNotification:(UI [RNNotifications didReceiveLocalNotification: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 +{ + // Update the badge count. Do not play sound or show an alert. For + // these options see + // https://developer.apple.com/documentation/usernotifications/unnotificationpresentationoptions?language=objc + completionHandler(UNNotificationPresentationOptionBadge); +} + @end