Last active
April 15, 2021 19:42
-
-
Save jehartzog/e363c7f55c2f4fe82bb7f757237ae549 to your computer and use it in GitHub Desktop.
New App AppDelegate.m For Iterable Build Issue
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 <React/RCTBridge.h> | |
#import <React/RCTBundleURLProvider.h> | |
#import <React/RCTRootView.h> | |
// UniModules per https://docs.expo.io/bare/installing-unimodules/ | |
#import <UMCore/UMModuleRegistry.h> | |
#import <UMReactNativeAdapter/UMNativeModulesProxy.h> | |
#import <UMReactNativeAdapter/UMModuleRegistryAdapter.h> | |
#ifdef FB_SONARKIT_ENABLED | |
#import <FlipperKit/FlipperClient.h> | |
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h> | |
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h> | |
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h> | |
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h> | |
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h> | |
// For Iterable | |
#import <UserNotifications/UserNotifications.h> | |
@import IterableSDK; | |
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; | |
@end | |
@implementation AppDelegate | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
#ifdef FB_SONARKIT_ENABLED | |
InitializeFlipper(application); | |
#endif | |
self.moduleRegistryAdapter = [[UMModuleRegistryAdapter alloc] initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc] init]]; | |
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; | |
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge | |
moduleName:@"social" | |
initialProperties:nil]; | |
if (@available(iOS 13.0, *)) { | |
rootView.backgroundColor = [UIColor systemBackgroundColor]; | |
} else { | |
rootView.backgroundColor = [UIColor whiteColor]; | |
} | |
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; | |
UIViewController *rootViewController = [UIViewController new]; | |
rootViewController.view = rootView; | |
self.window.rootViewController = rootViewController; | |
[self.window makeKeyAndVisible]; | |
//ITBL: Setup Notifications | |
[self setupNotifications]; | |
return YES; | |
} | |
- (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 | |
{ | |
#if DEBUG | |
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; | |
#else | |
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; | |
#endif | |
} | |
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { | |
[IterableAppIntegration application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; | |
} | |
#pragma mark - notification registration | |
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { | |
[IterableAPI registerToken:deviceToken]; | |
} | |
#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]; | |
} | |
#pragma mark - private | |
- (void) setupNotifications { | |
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; | |
center.delegate = self; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment