|
5 | 5 | #import <React/RCTRootView.h>
|
6 | 6 | #import <React/RCTPushNotificationManager.h>
|
7 | 7 | #import <RNBranch/RNBranch.h>
|
8 |
| -#if DEBUG |
9 |
| -#ifdef FB_SONARKIT_ENABLED |
10 |
| -#import <FlipperKit/FlipperClient.h> |
11 |
| -#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h> |
12 |
| -#import <FlipperKitLayoutPlugin/SKDescriptorMapper.h> |
13 |
| -#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h> |
14 |
| -#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h> |
15 |
| -#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h> |
16 |
| -#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h> |
17 |
| -#endif |
18 |
| -#endif |
| 8 | +#import <UserNotifications/UserNotifications.h> |
19 | 9 |
|
20 | 10 | #if DEBUG
|
21 | 11 | #include <EXDevLauncher/EXDevLauncherController.h>
|
22 | 12 | #endif
|
23 | 13 |
|
24 |
| -@implementation AppDelegate |
| 14 | +#import <Expo/Expo.h> // Required for `EXReactDelegateWrapper` |
25 | 15 |
|
26 |
| -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ |
| 16 | +@interface AppDelegate () |
27 | 17 |
|
28 |
| - self.moduleName = @"MetaMask"; |
| 18 | +@property (nonatomic, strong) EXReactDelegateWrapper *reactDelegate; |
29 | 19 |
|
30 |
| - [FIRApp configure]; |
31 |
| - NSString *foxCodeFromBundle = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"fox_code"]; |
| 20 | +@end |
32 | 21 |
|
33 |
| - NSString *foxCode; |
| 22 | +@implementation AppDelegate |
34 | 23 |
|
35 |
| - if(foxCodeFromBundle != nil){ |
36 |
| - foxCode = foxCodeFromBundle; |
37 |
| - } else { |
38 |
| - foxCode = @"debug"; |
39 |
| - } |
| 24 | +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { |
40 | 25 |
|
41 |
| - // Uncomment this line to use the test key instead of the live one. |
42 |
| - // [RNBranch useTestInstance]; |
43 |
| - [RNBranch initSessionWithLaunchOptions:launchOptions isReferrable:YES]; |
44 |
| - NSURL *jsCodeLocation; |
| 26 | + self.moduleName = @"MetaMask"; |
45 | 27 |
|
46 |
| - RCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:launchOptions]; |
47 |
| - RCTRootView *rootView = [self.reactDelegate createRootViewWithBridge:bridge |
48 |
| - moduleName:@"MetaMask" |
49 |
| - initialProperties:@{@"foxCode": foxCode}]; |
| 28 | + // Initialize Firebase |
| 29 | + if ([FIRApp defaultApp] == nil) { |
| 30 | + [FIRApp configure]; |
| 31 | + } |
50 | 32 |
|
51 |
| - self.initialProps = @{@"foxCode": foxCode}; |
52 | 33 |
|
53 |
| - rootView.backgroundColor = [UIColor colorNamed:@"ThemeColors"]; |
| 34 | + // Initialize Branch.io |
| 35 | + [RNBranch initSessionWithLaunchOptions:launchOptions isReferrable:YES]; |
54 | 36 |
|
| 37 | + NSString *foxCodeFromBundle = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"fox_code"]; |
| 38 | + NSString *foxCode = foxCodeFromBundle ? foxCodeFromBundle : @"debug"; |
| 39 | + |
| 40 | + // Create RootViewController |
55 | 41 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
56 |
| - UIViewController *rootViewController = [self.reactDelegate createRootViewController]; |
57 |
| - rootViewController.view = rootView; |
| 42 | + UIViewController *rootViewController = [self createRootViewController]; |
58 | 43 | self.window.rootViewController = rootViewController;
|
59 | 44 | [self.window makeKeyAndVisible];
|
60 | 45 |
|
61 |
| - //Keep splash screen while loading the bundle |
62 |
| - UIView* launchScreenView = [[[NSBundle mainBundle] loadNibNamed:@"LaunchScreen" owner:self options:nil] objectAtIndex:0]; |
63 |
| - launchScreenView.frame = self.window.bounds; |
64 |
| - rootView.loadingView = launchScreenView; |
| 46 | + self.initialProps = @{@"foxCode": foxCode}; |
65 | 47 |
|
66 |
| - [self initializeFlipper:application]; |
| 48 | + // Register for Push Notifications |
| 49 | + UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; |
| 50 | + center.delegate = self; |
| 51 | + [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge) |
| 52 | + completionHandler:^(BOOL granted, NSError * _Nullable error) { |
| 53 | + if (!error) { |
| 54 | + dispatch_async(dispatch_get_main_queue(), ^{ |
| 55 | + [application registerForRemoteNotifications]; |
| 56 | + }); |
| 57 | + } |
| 58 | + }]; |
| 59 | + |
| 60 | + return [super application:application didFinishLaunchingWithOptions:launchOptions]; |
| 61 | +} |
67 | 62 |
|
68 |
| - //Uncomment the following line to enable the splashscreen on ios |
69 |
| - //[RNSplashScreen show]; |
70 | 63 |
|
71 |
| - [super application:application didFinishLaunchingWithOptions:launchOptions]; |
| 64 | +// Push Notification Registration |
| 65 | +- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { |
| 66 | + [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; |
| 67 | +} |
72 | 68 |
|
73 |
| - return YES; |
| 69 | +- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { |
| 70 | + [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error]; |
74 | 71 | }
|
75 | 72 |
|
76 |
| -- (void) initializeFlipper:(UIApplication *)application { |
77 |
| - #if DEBUG |
78 |
| - #ifdef FB_SONARKIT_ENABLED |
79 |
| - FlipperClient *client = [FlipperClient sharedClient]; |
80 |
| - SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; |
81 |
| - [client addPlugin: [[FlipperKitLayoutPlugin alloc] initWithRootNode: application withDescriptorMapper: layoutDescriptorMapper]]; |
82 |
| - [client addPlugin: [[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; |
83 |
| - [client addPlugin: [FlipperKitReactPlugin new]]; |
84 |
| - [client addPlugin: [[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; |
85 |
| - [client start]; |
86 |
| - #endif |
87 |
| - #endif |
| 73 | +// Handle Push Notifications |
| 74 | +- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo |
| 75 | + fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { |
| 76 | + [RCTPushNotificationManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; |
88 | 77 | }
|
89 | 78 |
|
90 |
| -- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options |
91 |
| -{ |
| 79 | +// Handle Deep Links (Branch.io) |
| 80 | +- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options { |
92 | 81 | #if DEBUG
|
93 | 82 | if ([EXDevLauncherController.sharedInstance onDeepLink:url options:options]) {
|
94 |
| - return true; |
| 83 | + return YES; |
95 | 84 | }
|
96 | 85 | #endif
|
97 | 86 | return [RNBranch application:app openURL:url options:options];
|
98 | 87 | }
|
99 | 88 |
|
| 89 | +// Handle Universal Links |
100 | 90 | - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
|
101 | 91 | return [RNBranch continueUserActivity:userActivity];
|
102 | 92 | }
|
103 | 93 |
|
104 |
| -// Required to register for notifications |
105 |
| -- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings |
106 |
| -{ |
107 |
| - [RCTPushNotificationManager didRegisterUserNotificationSettings:notificationSettings]; |
108 |
| -} |
109 |
| -// Required for the register event. |
110 |
| -- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken |
111 |
| -{ |
112 |
| - [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; |
113 |
| -} |
114 |
| -// Required for the notification event. You must call the completion handler after handling the remote notification. |
115 |
| -- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo |
116 |
| -fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler |
117 |
| -{ |
118 |
| - [RCTPushNotificationManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; |
119 |
| -} |
120 |
| -// Required for the registrationError event. |
121 |
| -- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error |
122 |
| -{ |
123 |
| - [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error]; |
124 |
| -} |
125 |
| -// Required for the localNotification event. |
126 |
| -- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification |
127 |
| -{ |
128 |
| - [RCTPushNotificationManager didReceiveLocalNotification:notification]; |
| 94 | +// Get Bundle URL for React Native |
| 95 | +- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { |
| 96 | + #if DEBUG |
| 97 | + return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@".expo/.virtual-metro-entry"]; |
| 98 | + #else |
| 99 | + return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; |
| 100 | + #endif |
129 | 101 | }
|
130 | 102 |
|
131 |
| -- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge |
132 |
| -{ |
133 |
| -#if DEBUG |
134 |
| - return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@".expo/.virtual-metro-entry"]; |
135 |
| -#else |
136 |
| - return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; |
137 |
| -#endif |
| 103 | +// ✅ This method is inherited from EXAppDelegateWrapper |
| 104 | +- (UIViewController *)createRootViewController { |
| 105 | + return [super createRootViewController]; |
138 | 106 | }
|
139 | 107 |
|
140 | 108 | @end
|
0 commit comments