Created
January 20, 2022 16:36
-
-
Save blarzHernandez/36cfc61c00428fa78d8088dcbdd20d7e to your computer and use it in GitHub Desktop.
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
#import "AppDelegate.h" | |
@import IterableSDK; | |
#import <React/RCTBridge.h> | |
#import <React/RCTBundleURLProvider.h> | |
#import <React/RCTRootView.h> | |
#import <React/RCTLinkingManager.h> | |
#import <UMCore/UMModuleRegistry.h> | |
#import <UMReactNativeAdapter/UMNativeModulesProxy.h> | |
#import <UMReactNativeAdapter/UMModuleRegistryAdapter.h> | |
#import <EXSplashScreen/EXSplashScreenService.h> | |
#import <UMCore/UMModuleRegistryProvider.h> | |
#import <UserNotifications/UserNotifications.h> | |
#import <Firebase.h> | |
#if defined(FB_SONARKIT_ENABLED) && __has_include(<FlipperKit/FlipperClient.h>) | |
#import <FlipperKit/FlipperClient.h> | |
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h> | |
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h> | |
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h> | |
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h> | |
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h> | |
static void InitializeFlipper(UIApplication *application) { | |
FlipperClient *client = [FlipperClient sharedClient]; | |
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; | |
[client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]]; | |
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; | |
[client addPlugin:[FlipperKitReactPlugin new]]; | |
[client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; | |
[client start]; | |
} | |
#endif | |
@interface AppDelegate () <RCTBridgeDelegate> | |
@property (nonatomic, strong) UMModuleRegistryAdapter *moduleRegistryAdapter; | |
@property (nonatomic, strong) NSDictionary *launchOptions; | |
@end | |
@implementation AppDelegate | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
if ([FIRApp defaultApp] == nil) { | |
[FIRApp configure]; | |
} | |
[self setupNotifications]; | |
#if defined(FB_SONARKIT_ENABLED) && __has_include(<FlipperKit/FlipperClient.h>) | |
InitializeFlipper(application); | |
#endif | |
self.moduleRegistryAdapter = [[UMModuleRegistryAdapter alloc] initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc] init]]; | |
self.launchOptions = launchOptions; | |
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; | |
#ifdef DEBUG | |
[self initializeReactNativeApp]; | |
#else | |
EXUpdatesAppController *controller = [EXUpdatesAppController sharedInstance]; | |
controller.delegate = self; | |
[controller startAndShowLaunchScreen:self.window]; | |
#endif | |
[super application:application didFinishLaunchingWithOptions:launchOptions]; | |
return YES; | |
} | |
- (RCTBridge *)initializeReactNativeApp | |
{ | |
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:self.launchOptions]; | |
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"main" initialProperties:nil]; | |
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; | |
UIViewController *rootViewController = [UIViewController new]; | |
rootViewController.view = rootView; | |
self.window.rootViewController = rootViewController; | |
[self.window makeKeyAndVisible]; | |
return bridge; | |
} | |
- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge | |
{ | |
NSArray<id<RCTBridgeModule>> *extraModules = [_moduleRegistryAdapter extraModulesForBridge:bridge]; | |
// If you'd like to export some custom RCTBridgeModules that are not Expo modules, add them here! | |
return extraModules; | |
} | |
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { | |
#ifdef DEBUG | |
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; | |
#else | |
return [[EXUpdatesAppController sharedInstance] launchAssetUrl]; | |
#endif | |
} | |
- (void)appController:(EXUpdatesAppController *)appController didStartWithSuccess:(BOOL)success { | |
appController.bridge = [self initializeReactNativeApp]; | |
EXSplashScreenService *splashScreenService = (EXSplashScreenService *)[UMModuleRegistryProvider getSingletonModuleForClass:[EXSplashScreenService class]]; | |
[splashScreenService showSplashScreenFor:self.window.rootViewController]; | |
} | |
// Linking API | |
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options { | |
return [RCTLinkingManager application:application openURL:url options:options]; | |
} | |
// Universal Links | |
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler { | |
return [RCTLinkingManager application:application | |
continueUserActivity:userActivity | |
restorationHandler:restorationHandler]; | |
} | |
#pragma mark - UNUserNotificationCenterDelegate | |
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler { | |
completionHandler(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound); | |
} | |
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { | |
[IterableAppIntegration userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler]; | |
} | |
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { | |
[IterableAPI registerToken:deviceToken]; | |
} | |
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { | |
[IterableAppIntegration application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; | |
} | |
// ... | |
#pragma mark - private | |
- (void) setupNotifications { | |
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; | |
center.delegate = self; | |
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) { | |
if (granted) { | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
// ... | |
}); | |
} | |
}]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment