AppDelegate.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #import "AppDelegate.h"
  2. #import <React/RCTBridge.h>
  3. #import <React/RCTBundleURLProvider.h>
  4. #import <React/RCTRootView.h>
  5. #import <MMKV/MMKV.h>
  6. #import <UserNotifications/UserNotifications.h>
  7. #import <RNCPushNotificationIOS.h>
  8. #ifdef FB_SONARKIT_ENABLED
  9. #import <FlipperKit/FlipperClient.h>
  10. #import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
  11. #import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
  12. #import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
  13. #import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
  14. #import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
  15. static void InitializeFlipper(UIApplication *application) {
  16. FlipperClient *client = [FlipperClient sharedClient];
  17. SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
  18. [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
  19. [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
  20. [client addPlugin:[FlipperKitReactPlugin new]];
  21. [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
  22. [client start];
  23. }
  24. #endif
  25. @implementation AppDelegate
  26. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  27. {
  28. #ifdef FB_SONARKIT_ENABLED
  29. InitializeFlipper(application);
  30. #endif
  31. // init MMKV in the main thread
  32. [MMKV initializeMMKV:nil];
  33. RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  34. RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
  35. moduleName:@"Umora"
  36. initialProperties:nil];
  37. if (@available(iOS 13.0, *)) {
  38. rootView.backgroundColor = [UIColor systemBackgroundColor];
  39. } else {
  40. rootView.backgroundColor = [UIColor whiteColor];
  41. }
  42. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  43. UIViewController *rootViewController = [UIViewController new];
  44. rootViewController.view = rootView;
  45. self.window.rootViewController = rootViewController;
  46. [self.window makeKeyAndVisible];
  47. // ---- push-notification-ios ----- //
  48. // Define UNUserNotificationCenter
  49. UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  50. center.delegate = self;
  51. // ---- push-notification-ios ----- //
  52. return YES;
  53. }
  54. - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
  55. {
  56. #if DEBUG
  57. return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
  58. #else
  59. return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
  60. #endif
  61. }
  62. // ---- push-notification-ios ----- //
  63. //Called when a notification is delivered to a foreground app.
  64. -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
  65. {
  66. completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge);
  67. }
  68. // Required for the register event.
  69. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
  70. {
  71. [RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
  72. }
  73. // Required for the notification event. You must call the completion handler after handling the remote notification.
  74. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
  75. fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
  76. {
  77. [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
  78. }
  79. // Required for the registrationError event.
  80. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
  81. {
  82. [RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error];
  83. }
  84. // Required for localNotification event
  85. - (void)userNotificationCenter:(UNUserNotificationCenter *)center
  86. didReceiveNotificationResponse:(UNNotificationResponse *)response
  87. withCompletionHandler:(void (^)(void))completionHandler
  88. {
  89. [RNCPushNotificationIOS didReceiveNotificationResponse:response];
  90. }
  91. // ---- push-notification-ios ----- //
  92. @end