|
7 | 7 |
|
8 | 8 | #import "AppDelegate.h" |
9 | 9 |
|
10 | | -#if RNTESTER_USE_APPDELEGATE |
11 | | - |
12 | 10 | #if !TARGET_OS_TV |
13 | 11 | #import <UserNotifications/UserNotifications.h> |
14 | | -#endif |
15 | | - |
16 | | -#import <React/RCTBundleURLProvider.h> |
17 | | -#import <React/RCTDefines.h> |
18 | | -#import <React/RCTLinkingManager.h> |
19 | | -#import <ReactCommon/RCTSampleTurboModule.h> |
20 | | -#import <ReactCommon/RCTTurboModuleManager.h> |
21 | | - |
22 | | -#if !TARGET_OS_TV |
23 | 12 | #import <React/RCTPushNotificationManager.h> |
24 | 13 | #endif |
25 | 14 |
|
26 | | -#import <NativeCxxModuleExample/NativeCxxModuleExample.h> |
27 | | -#ifndef RN_DISABLE_OSS_PLUGIN_HEADER |
28 | | -#import <RNTMyNativeViewComponentView.h> |
29 | | -#endif |
30 | | - |
31 | | -#if __has_include(<ReactAppDependencyProvider/RCTAppDependencyProvider.h>) |
32 | | -#define USE_OSS_CODEGEN 1 |
33 | | -#import <ReactAppDependencyProvider/RCTAppDependencyProvider.h> |
34 | | -#else |
35 | | -#define USE_OSS_CODEGEN 0 |
36 | | -#endif |
37 | | - |
38 | | -#if RCT_DEV_MENU |
39 | | -#import <React/RCTDevMenu.h> |
40 | | -#endif |
41 | | - |
42 | | -static NSString *kBundlePath = @"js/RNTesterApp.ios"; |
43 | | - |
44 | 15 | #if !TARGET_OS_TV |
45 | 16 | @interface AppDelegate () <UNUserNotificationCenterDelegate> |
46 | 17 | @end |
47 | | -#else |
48 | | -@interface AppDelegate () |
49 | | -@end |
50 | 18 | #endif |
51 | 19 |
|
52 | 20 | @implementation AppDelegate |
53 | 21 |
|
54 | 22 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions |
55 | 23 | { |
56 | | - self.reactNativeFactory = [[RCTReactNativeFactory alloc] initWithDelegate:self]; |
57 | | -#if USE_OSS_CODEGEN |
58 | | - self.dependencyProvider = [RCTAppDependencyProvider new]; |
59 | | -#endif |
60 | | - |
61 | | -#if RCT_DEV_MENU |
62 | | - |
63 | | - RCTDevMenuConfiguration *devMenuConfiguration = [[RCTDevMenuConfiguration alloc] initWithDevMenuEnabled:true |
64 | | - shakeGestureEnabled:true |
65 | | - keyboardShortcutsEnabled:true]; |
66 | | - [self.reactNativeFactory setDevMenuConfiguration:devMenuConfiguration]; |
67 | | - |
68 | | -#endif |
69 | | - |
70 | | - self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; |
71 | | - |
72 | | - [self.reactNativeFactory startReactNativeWithModuleName:@"RNTesterApp" |
73 | | - inWindow:self.window |
74 | | - initialProperties:[self prepareInitialProps] |
75 | | - launchOptions:launchOptions]; |
76 | | - |
77 | 24 | #if !TARGET_OS_TV |
78 | 25 | [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self]; |
79 | 26 | #endif |
80 | | - |
81 | 27 | return YES; |
82 | 28 | } |
83 | 29 |
|
84 | | -- (NSDictionary *)prepareInitialProps |
85 | | -{ |
86 | | - NSMutableDictionary *initProps = [NSMutableDictionary new]; |
87 | | - |
88 | | - NSString *_routeUri = [[NSUserDefaults standardUserDefaults] stringForKey:@"route"]; |
89 | | - if (_routeUri) { |
90 | | - initProps[@"exampleFromAppetizeParams"] = [NSString stringWithFormat:@"rntester://example/%@Example", _routeUri]; |
91 | | - } |
92 | | - |
93 | | - return initProps; |
94 | | -} |
95 | | - |
96 | | -- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge |
97 | | -{ |
98 | | - return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:kBundlePath]; |
99 | | -} |
100 | | - |
101 | | -- (BOOL)application:(UIApplication *)app |
102 | | - openURL:(NSURL *)url |
103 | | - options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options |
104 | | -{ |
105 | | - return [RCTLinkingManager application:app openURL:url options:options]; |
106 | | -} |
107 | | - |
108 | | -- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name |
109 | | - jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker |
110 | | -{ |
111 | | - if (name == facebook::react::NativeCxxModuleExample::kModuleName) { |
112 | | - return std::make_shared<facebook::react::NativeCxxModuleExample>(jsInvoker); |
113 | | - } |
114 | | - |
115 | | - return [super getTurboModule:name jsInvoker:jsInvoker]; |
116 | | -} |
117 | | - |
118 | 30 | #if !TARGET_OS_TV |
119 | 31 | // Required for the remoteNotificationsRegistered event. |
120 | 32 | - (void)application:(__unused UIApplication *)application |
@@ -161,85 +73,4 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center |
161 | 73 | } |
162 | 74 | #endif |
163 | 75 |
|
164 | | -#pragma mark - RCTComponentViewFactoryComponentProvider |
165 | | - |
166 | | -#ifndef RN_DISABLE_OSS_PLUGIN_HEADER |
167 | | -- (nonnull NSDictionary<NSString *, Class<RCTComponentViewProtocol>> *)thirdPartyFabricComponents |
168 | | -{ |
169 | | - NSMutableDictionary *dict = [super thirdPartyFabricComponents].mutableCopy; |
170 | | - if (!dict[@"RNTMyNativeView"]) { |
171 | | - dict[@"RNTMyNativeView"] = NSClassFromString(@"RNTMyNativeViewComponentView"); |
172 | | - } |
173 | | - if (!dict[@"SampleNativeComponent"]) { |
174 | | - dict[@"SampleNativeComponent"] = NSClassFromString(@"RCTSampleNativeComponentComponentView"); |
175 | | - } |
176 | | - return dict; |
177 | | -} |
178 | | -#endif |
179 | | - |
180 | | -- (NSURL *)bundleURL |
181 | | -{ |
182 | | - return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:kBundlePath]; |
183 | | -} |
184 | | - |
185 | | -@end |
186 | | -#else |
187 | | - |
188 | | -#if !TARGET_OS_TV |
189 | | -#import <UserNotifications/UserNotifications.h> |
190 | | -#import <React/RCTPushNotificationManager.h> |
191 | | -#endif |
192 | | - |
193 | | -#if !TARGET_OS_TV |
194 | | -@interface AppDelegate () <UNUserNotificationCenterDelegate> |
195 | | -@end |
196 | | -#endif |
197 | | - |
198 | | -@implementation AppDelegate |
199 | | - |
200 | | -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions |
201 | | -{ |
202 | | -#if !TARGET_OS_TV |
203 | | - [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self]; |
204 | | -#endif |
205 | | - return YES; |
206 | | -} |
207 | | - |
208 | | -#if !TARGET_OS_TV |
209 | | -- (void)application:(__unused UIApplication *)application |
210 | | - didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken |
211 | | -{ |
212 | | - [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; |
213 | | -} |
214 | | - |
215 | | -- (void)application:(__unused UIApplication *)application |
216 | | - didFailToRegisterForRemoteNotificationsWithError:(NSError *)error |
217 | | -{ |
218 | | - [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error]; |
219 | | -} |
220 | | - |
221 | | -- (void)userNotificationCenter:(UNUserNotificationCenter *)center |
222 | | - willPresentNotification:(UNNotification *)notification |
223 | | - withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler |
224 | | -{ |
225 | | - [RCTPushNotificationManager didReceiveNotification:notification]; |
226 | | - completionHandler(UNNotificationPresentationOptionNone); |
227 | | -} |
228 | | - |
229 | | -- (void)userNotificationCenter:(UNUserNotificationCenter *)center |
230 | | - didReceiveNotificationResponse:(UNNotificationResponse *)response |
231 | | - withCompletionHandler:(void (^)(void))completionHandler |
232 | | -{ |
233 | | - UNNotification *notification = response.notification; |
234 | | - |
235 | | - if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) { |
236 | | - [RCTPushNotificationManager setInitialNotification:notification]; |
237 | | - } |
238 | | - |
239 | | - [RCTPushNotificationManager didReceiveNotification:notification]; |
240 | | - completionHandler(); |
241 | | -} |
242 | | -#endif |
243 | | - |
244 | 76 | @end |
245 | | -#endif |
0 commit comments