Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "AppDelegate.h"
- #import "ReactNativeConfig.h"
- #import <React/RCTBundleURLProvider.h>
- // BRAZE
- #import <BrazeKit/BrazeKit-Swift.h>
- #import "BrazeReactBridge.h"
- #import "BrazeReactUtils.h"
- // BOOT SPLASH SCREEN
- #import "RNBootSplash.h"
- // EMBRACE
- #import <Embrace/Embrace.h>
- // BRANCH
- #import <RNBranch/RNBranch.h>
- // CHROMECAST
- #import <GoogleCast/GoogleCast.h>
- // CODEPUSH
- #import <CodePush/CodePush.h>
- // ORIENTATION
- #import "Orientation.h"
- // CARPLAY
- #import <RNCarPlay.h>
- // SDImage (WebP Support)
- #import "SDImageCodersManager.h"
- #import <SDWebImageWebPCoder/SDImageWebPCoder.h>
- #import "CarScene.h"
- #import "MobileScene.h"
- @implementation AppDelegate
- #pragma mark - RCTAppDelegate
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- self.moduleName = @"wondery";
- // You can add your custom initial props in the dictionary below.
- // They will be passed down to the ViewController used by React Native.
- self.initialProps = @{};
- // CHROMECAST ************************************************************
- NSString *receiverAppID = [ReactNativeConfig envFor:@"CHROMECAST_RECEIVER_ID"];
- GCKDiscoveryCriteria *criteria = [[GCKDiscoveryCriteria alloc] initWithApplicationID:receiverAppID];
- GCKCastOptions* options = [[GCKCastOptions alloc] initWithDiscoveryCriteria:criteria];
- options.suspendSessionsWhenBackgrounded = false;
- [GCKCastContext setSharedInstanceWithOptions:options];
- // ************************************************************************
- // BRAZE *****************************************************************
- NSString *brazeKey = [ReactNativeConfig envFor:@"BRAZE_KEY_IOS"];
- NSString *brazeEndpoint = [ReactNativeConfig envFor:@"BRAZE_ENDPOINT"];
- BRZConfiguration *configuration = [[BRZConfiguration alloc] initWithApiKey:brazeKey
- endpoint:brazeEndpoint];
- Braze *braze = [BrazeReactBridge initBraze:configuration];
- AppDelegate.braze = braze;
- [application registerForRemoteNotifications];
- UNUserNotificationCenter *center = UNUserNotificationCenter.currentNotificationCenter;
- [center setNotificationCategories:BRZNotifications.categories];
- center.delegate = self;
- UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge | UNAuthorizationOptionProvisional;
- [center requestAuthorizationWithOptions:authOptions
- completionHandler:^(BOOL granted, NSError *_Nullable error) {
- NSLog(@"Notification authorization, granted: %d, "
- @"error: %@)",
- granted, error);
- }];
- [[BrazeReactUtils sharedInstance] populateInitialUrlFromLaunchOptions:launchOptions];
- // ************************************************************************
- // BRANCH *****************************************************************
- bool isProduction = [@"PROD" isEqualToString: [ReactNativeConfig envFor:@"ENV_NAME"]];
- if (!isProduction) {
- [RNBranch useTestInstance];
- }
- [RNBranch.branch checkPasteboardOnInstall];
- [RNBranch initSessionWithLaunchOptions:launchOptions isReferrable:YES];
- // *************************************************************************
- // EMBRACE *****************************************************************
- NSString *embraceAppIdIOS = [ReactNativeConfig envFor:@"EMBRACE_APP_ID_IOS"];
- [[Embrace sharedInstance] startWithKey:embraceAppIdIOS launchOptions: launchOptions framework:EMBAppFrameworkReactNative];
- // ***********************************************************************
- // PENTHERA **************************************************************
- #ifdef DEBUG
- // Development best practice
- [VirtuosoLogger setLogLevel:kVL_LogVerbose];
- #else
- // Production best practice
- [VirtuosoLogger setLogLevel:kVL_LogError];
- #endif
- // ***********************************************************************
- // Animated WEBP Support *************************************************
- [SDImageCodersManager.sharedManager addCoder:SDImageWebPCoder.sharedCoder];
- // ***********************************************************************
- return [super application:application didFinishLaunchingWithOptions:launchOptions];
- }
- - (UIViewController *)createRootViewController {
- UIViewController * vc = [[UIViewController alloc] init];
- self.rootViewController = vc;
- return vc;
- }
- - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
- moduleName:(NSString *)moduleName
- initProps:(NSDictionary *)initProps {
- UIView *rootView = [super createRootViewWithBridge:bridge
- moduleName:moduleName
- initProps:initProps];
- if (@available(iOS 13.0, *)) {
- self.bridge = bridge;
- self.rootView = (RCTRootView*)rootView;
- }
- [RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView]; // â¬…ï¸ initialize the splash screen
- return rootView;
- }
- - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
- #if DEBUG
- return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
- #else
- // return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
- // Replace above line with the following to enable CodePush. This change configures your app to always load the most recent version of your app's JS bundle.
- // On the first launch, this corresponds to the file that was compiled with the app. However, after an update has been pushed via CodePush,
- // this returns the location of the most recently installed update. NOTE: this will only use CodePush to resolve your JS bundle within RELEASE BUILDS.
- return [CodePush bundleURL];
- #endif
- }
- /// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
- ///
- /// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
- /// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
- /// @return: `true` if the `concurrentRoot` feature is enabled. Otherwise, it returns `false`.
- - (BOOL)concurrentRootEnabled
- {
- return true;
- }
- #pragma mark SceneDelegate
- - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
- if([[connectingSceneSession role] isEqualToString:@"CPTemplateApplicationSceneSessionRoleApplication"]) {
- UISceneConfiguration *scene = [[UISceneConfiguration alloc] initWithName:@"CarPlay" sessionRole:connectingSceneSession.role];
- [scene setDelegateClass:CarSceneDelegate.class]; //TODO
- return scene;
- } else {
- UISceneConfiguration *scene = [[UISceneConfiguration alloc] initWithName:@"Mobile" sessionRole:connectingSceneSession.role];
- [scene setDelegateClass:MobileSceneDelegate.class]; //TODO
- return scene;
- }
- }
- - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
- }
- #pragma mark - AppDelegate.braze
- static Braze *_braze = nil;
- + (Braze *)braze {
- return _braze;
- }
- + (void)setBraze:(Braze *)braze {
- _braze = braze;
- }
- #pragma mark BRAZE Push
- - (void)registerForPushNotifications {
- UNUserNotificationCenter *center = UNUserNotificationCenter.currentNotificationCenter;
- [center setNotificationCategories:BRZNotifications.categories];
- center.delegate = self;
- [UIApplication.sharedApplication registerForRemoteNotifications];
- // Authorization is requested later in the JavaScript layer via `Braze.requestPushPermission`.
- }
- - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
- BOOL processedByBraze = AppDelegate.braze != nil && [AppDelegate.braze.notifications handleBackgroundNotificationWithUserInfo:userInfo
- fetchCompletionHandler:completionHandler];
- if (processedByBraze) {
- return;
- }
- completionHandler(UIBackgroundFetchResultNoData);
- }
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center
- didReceiveNotificationResponse:(UNNotificationResponse *)response
- withCompletionHandler:(void (^)(void))completionHandler {
- BOOL processedByBraze = AppDelegate.braze != nil && [AppDelegate.braze.notifications handleUserNotificationWithResponse:response
- withCompletionHandler:completionHandler];
- if (processedByBraze) {
- return;
- }
- completionHandler();
- }
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center
- willPresentNotification:(UNNotification *)notification
- withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
- if (@available(iOS 14.0, *)) {
- completionHandler(UNNotificationPresentationOptionList | UNNotificationPresentationOptionBanner);
- } else {
- completionHandler(UNNotificationPresentationOptionAlert);
- }
- }
- - (void)application:(UIApplication *)application
- didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
- [AppDelegate.braze.notifications registerDeviceToken:deviceToken];
- }
- #pragma mark BRANCH react-native-branch
- // react-native-branch AppDelegate calls moved above to SceneDelegate for iOS13+
- - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
- if ([RNBranch application:app openURL:url options:options]) {
- // do other deep link routing for the Facebook SDK, Pinterest SDK, etc
- }
- return YES;
- }
- - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler {
- return [RNBranch continueUserActivity:userActivity];
- }
- - (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity {
- [RNBranch continueUserActivity:userActivity];
- }
- - (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
- UIOpenURLContext *context = [URLContexts allObjects].firstObject;
- if (context) {
- NSMutableDictionary *options = [NSMutableDictionary dictionary];
- options[UIApplicationOpenURLOptionsSourceApplicationKey] = context.options.sourceApplication;
- options[UIApplicationOpenURLOptionsAnnotationKey] = context.options.annotation;
- [RNBranch application:UIApplication.sharedApplication openURL:context.URL options:options];
- }
- }
- #pragma mark ORIENTATION
- - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
- return [Orientation getOrientation];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement