-
-
Save simistern/352a46a4881fd47f7940cab123163783 to your computer and use it in GitHub Desktop.
APpDelegate
This file contains hidden or 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 <RNBranch/RNBranch.h> | |
#import <React/RCTBridge.h> | |
#import <React/RCTBundleURLProvider.h> | |
#import <React/RCTRootView.h> | |
#import <React/RCTLinkingManager.h> | |
#import <AppCenterReactNative.h> | |
#import <AppCenterReactNativeAnalytics.h> | |
#import <AppCenterReactNativeCrashes.h> | |
#import <CodePush/CodePush.h> | |
#import <Lottie/lottie-ios-umbrella.h> | |
#import <UMCore/UMModuleRegistry.h> | |
#import <UMReactNativeAdapter/UMNativeModulesProxy.h> | |
#import <UMReactNativeAdapter/UMModuleRegistryAdapter.h> | |
#import <UserNotifications/UserNotifications.h> | |
#import <RNCPushNotificationIOS.h> | |
#import "SEGAppboyIntegrationFactory.h" | |
#import <Analytics/SEGAnalytics.h> | |
#import "Appboy-iOS-SDK/AppboyKit.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> | |
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, UNUserNotificationCenterDelegate> | |
@property (nonatomic, strong) UMModuleRegistryAdapter *moduleRegistryAdapter; | |
@end | |
@implementation AppDelegate | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
#ifdef FB_SONARKIT_ENABLED | |
InitializeFlipper(application); | |
#endif | |
// enable pasteboard check for iOS 15+ only | |
if ([[[UIDevice currentDevice] systemVersion] compare:@"15.0" options:NSNumericSearch] != NSOrderedAscending) | |
// Branch initialization for NativeLink | |
[RNBranch.branch checkPasteboardOnInstall]; | |
[RNBranch initSessionWithLaunchOptions:launchOptions isReferrable:YES]; | |
// defaulting to older style datepicker | |
if (@available(iOS 14, *)) { | |
UIDatePicker *picker = [UIDatePicker appearance]; | |
picker.preferredDatePickerStyle = UIDatePickerStyleWheels; | |
} | |
// Segment analytics | |
NSString* segWriteKey = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"Segment Write Key"]; | |
SEGAnalyticsConfiguration* configuration = [SEGAnalyticsConfiguration configurationWithWriteKey:segWriteKey]; | |
configuration.launchOptions = launchOptions; | |
[configuration use:[SEGAppboyIntegrationFactory instance]]; | |
[SEGAnalytics setupWithConfiguration:configuration]; | |
UNAuthorizationOptions options = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge; | |
if (@available(iOS 12.0, *)) { | |
options = options | UNAuthorizationOptionProvisional; | |
} | |
// Push Notifications | |
if (@available(iOS 10.0, *)) { | |
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; | |
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) { | |
if (settings.authorizationStatus != UNAuthorizationStatusNotDetermined) { | |
// authorization has already been requested, need to follow usual steps | |
[center requestAuthorizationWithOptions:(options) completionHandler:^(BOOL granted, NSError * _Nullable error) { | |
[[Appboy sharedInstance] pushAuthorizationFromUserNotificationCenter:granted]; | |
}]; | |
center.delegate = self; | |
[center setNotificationCategories:[ABKPushUtils getAppboyUNNotificationCategorySet]]; | |
[[UIApplication sharedApplication] registerForRemoteNotifications]; | |
} | |
}]; | |
} else { | |
UIApplication *sharedApplication = [UIApplication sharedApplication]; | |
UIUserNotificationSettings *notificationSettings = [sharedApplication currentUserNotificationSettings]; | |
if (notificationSettings.types) { | |
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(options) categories:[ABKPushUtils getAppboyUIUserNotificationCategorySet]]; | |
[sharedApplication registerUserNotificationSettings:settings]; | |
[sharedApplication registerForRemoteNotifications]; | |
} | |
if (!notificationSettings.types) { | |
// … | |
// fire custom event | |
// ... | |
} | |
} | |
if (@available(iOS 10.0, *)) { | |
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; | |
[center requestAuthorizationWithOptions:(options) completionHandler:^(BOOL granted, NSError * _Nullable error) { | |
[[Appboy sharedInstance] pushAuthorizationFromUserNotificationCenter:granted]; | |
}]; | |
center.delegate = self; | |
[center setNotificationCategories:[ABKPushUtils getAppboyUNNotificationCategorySet]]; | |
[[UIApplication sharedApplication] registerForRemoteNotifications]; | |
} else { | |
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(options) categories:[ABKPushUtils getAppboyUIUserNotificationCategorySet]]; | |
UIApplication *sharedApplication = [UIApplication sharedApplication]; | |
[sharedApplication registerUserNotificationSettings:settings]; | |
[sharedApplication registerForRemoteNotifications]; | |
} | |
self.moduleRegistryAdapter = [[UMModuleRegistryAdapter alloc] initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc] init]]; | |
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; | |
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge | |
moduleName:@"OurApp" | |
initialProperties:nil]; | |
rootView.backgroundColor = [[UIColor alloc] initWithRed:0.0f green:0.0f blue:0.0f alpha:1]; | |
[AppCenterReactNative register]; | |
[AppCenterReactNativeAnalytics registerWithInitiallyEnabled:true]; | |
[AppCenterReactNativeCrashes registerWithAutomaticProcessing]; | |
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; | |
UIViewController *rootViewController = [UIViewController new]; | |
rootViewController.view = rootView; | |
self.window.rootViewController = rootViewController; | |
[self.window makeKeyAndVisible]; | |
[super application:application didFinishLaunchingWithOptions:launchOptions]; | |
return YES; | |
} | |
// Push Notifications | |
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken | |
{ | |
[[SEGAnalytics sharedAnalytics] registeredForRemoteNotificationsWithDeviceToken:deviceToken]; | |
[RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; | |
} | |
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo | |
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler | |
{ | |
[[SEGAnalytics sharedAnalytics] receivedRemoteNotification:userInfo]; | |
[[SEGAppboyIntegrationFactory instance] saveRemoteNotification:userInfo]; | |
[RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; | |
} | |
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error | |
{ | |
[RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error]; | |
} | |
- (void)userNotificationCenter:(UNUserNotificationCenter *)center | |
didReceiveNotificationResponse:(UNNotificationResponse *)response | |
withCompletionHandler:(void (^)(void))completionHandler | |
{ | |
[RNCPushNotificationIOS didReceiveNotificationResponse:response]; | |
[[SEGAppboyIntegrationFactory instance].appboyHelper userNotificationCenter:center receivedNotificationResponse:response]; | |
if (completionHandler) { | |
completionHandler(); | |
} | |
} | |
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler | |
{ | |
if (@available(iOS 14.0, *)) { | |
completionHandler(UNNotificationPresentationOptionList | UNNotificationPresentationOptionBanner); | |
} else { | |
completionHandler(UNNotificationPresentationOptionAlert); | |
} | |
} | |
// Deep Linking | |
- (BOOL)application:(UIApplication *)application | |
openURL:(NSURL *)url | |
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options | |
{ | |
if ([RNBranch application:application openURL:url options:options]) {} | |
return [RCTLinkingManager application:application openURL:url options:options]; | |
} | |
// Universal Links | |
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity | |
restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler | |
{ | |
[RNBranch continueUserActivity:userActivity]; | |
return [RCTLinkingManager application:application | |
continueUserActivity:userActivity | |
restorationHandler:restorationHandler]; | |
} | |
- (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:@"mobile/consumer-mobile/index" fallbackResource:nil]; | |
#else | |
return [CodePush bundleURL]; | |
#endif | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment