@@ -9,6 +9,9 @@ @implementation RNRadar {
99 CLLocationManager *locationManager;
1010 RCTPromiseResolveBlock permissionsRequestResolver;
1111 bool hasListeners;
12+ #ifdef RCT_NEW_ARCH_ENABLED
13+ bool jsEventEmitterReady;
14+ #endif
1215}
1316
1417RCT_EXPORT_MODULE ()
@@ -52,12 +55,21 @@ - (void)stopObserving {
5255 hasListeners = NO ;
5356}
5457
58+ #ifdef RCT_NEW_ARCH_ENABLED
59+ - (void )setEventEmitterCallback : (EventEmitterCallbackWrapper *)eventEmitterCallbackWrapper {
60+ [super setEventEmitterCallback: eventEmitterCallbackWrapper];
61+ jsEventEmitterReady = YES ;
62+ }
63+ #endif
64+
5565- (void )onNewInAppMessage : (RadarInAppMessage *)inAppMessage {
5666
5767 NSMutableDictionary *body = [NSMutableDictionary new ];
5868 [body setValue: [Radar dictionaryForInAppMessage: inAppMessage] forKey: @" inAppMessage" ];
5969 #ifdef RCT_NEW_ARCH_ENABLED
60- [self emitNewInAppMessageEmitter: body];
70+ if (jsEventEmitterReady) {
71+ [self emitNewInAppMessageEmitter: body];
72+ }
6173 #else
6274 if (hasListeners) {
6375 [self sendEventWithName: @" newInAppMessageEmitter" body: body];
@@ -69,7 +81,9 @@ - (void)onInAppMessageDismissed:(RadarInAppMessage *)inAppMessage {
6981 NSMutableDictionary *body = [NSMutableDictionary new ];
7082 [body setValue: [Radar dictionaryForInAppMessage: inAppMessage] forKey: @" inAppMessage" ];
7183 #ifdef RCT_NEW_ARCH_ENABLED
72- [self emitInAppMessageDismissedEmitter: body];
84+ if (jsEventEmitterReady) {
85+ [self emitInAppMessageDismissedEmitter: body];
86+ }
7387 #else
7488 if (hasListeners) {
7589 [self sendEventWithName: @" inAppMessageDismissedEmitter" body: body];
@@ -81,7 +95,9 @@ - (void)onInAppMessageButtonClicked:(RadarInAppMessage *)inAppMessage {
8195 NSMutableDictionary *body = [NSMutableDictionary new ];
8296 [body setValue: [Radar dictionaryForInAppMessage: inAppMessage] forKey: @" inAppMessage" ];
8397 #ifdef RCT_NEW_ARCH_ENABLED
84- [self emitInAppMessageClickedEmitter: body];
98+ if (jsEventEmitterReady) {
99+ [self emitInAppMessageClickedEmitter: body];
100+ }
85101 #else
86102 if (hasListeners) {
87103 [self sendEventWithName: @" inAppMessageClickedEmitter" body: body];
@@ -105,7 +121,9 @@ - (void)didReceiveEvents:(NSArray<RadarEvent *> *)events user:(RadarUser * _Null
105121 [body setValue: [user dictionaryValue ] forKey: @" user" ];
106122 }
107123 #ifdef RCT_NEW_ARCH_ENABLED
108- [self emitEventsEmitter: body];
124+ if (jsEventEmitterReady) {
125+ [self emitEventsEmitter: body];
126+ }
109127 #else
110128 if (hasListeners) {
111129 [self sendEventWithName: @" eventsEmitter" body: body];
@@ -115,10 +133,12 @@ - (void)didReceiveEvents:(NSArray<RadarEvent *> *)events user:(RadarUser * _Null
115133
116134- (void )didUpdateLocation : (CLLocation *)location user : (RadarUser *)user {
117135 #ifdef RCT_NEW_ARCH_ENABLED
118- [self emitLocationEmitter: @{
119- @" location" : [Radar dictionaryForLocation: location],
120- @" user" : [user dictionaryValue ]
121- }];
136+ if (jsEventEmitterReady) {
137+ [self emitLocationEmitter: @{
138+ @" location" : [Radar dictionaryForLocation: location],
139+ @" user" : [user dictionaryValue ]
140+ }];
141+ }
122142 #else
123143 if (hasListeners) {
124144 [self sendEventWithName: @" locationEmitter" body: @{
@@ -131,11 +151,13 @@ - (void)didUpdateLocation:(CLLocation *)location user:(RadarUser *)user {
131151
132152- (void )didUpdateClientLocation : (CLLocation *)location stopped : (BOOL )stopped source : (RadarLocationSource)source {
133153 #ifdef RCT_NEW_ARCH_ENABLED
134- [self emitClientLocationEmitter: @{
135- @" location" : [Radar dictionaryForLocation: location],
136- @" stopped" : @(stopped),
137- @" source" : [Radar stringForLocationSource: source]
138- }];
154+ if (jsEventEmitterReady) {
155+ [self emitClientLocationEmitter: @{
156+ @" location" : [Radar dictionaryForLocation: location],
157+ @" stopped" : @(stopped),
158+ @" source" : [Radar stringForLocationSource: source]
159+ }];
160+ }
139161 #else
140162 if (hasListeners) {
141163 [self sendEventWithName: @" clientLocationEmitter" body: @{
@@ -152,7 +174,9 @@ - (void)didFailWithStatus:(RadarStatus)status {
152174 @" status" : [Radar stringForStatus: status]
153175 };
154176 #ifdef RCT_NEW_ARCH_ENABLED
155- [self emitErrorEmitter: body];
177+ if (jsEventEmitterReady) {
178+ [self emitErrorEmitter: body];
179+ }
156180 #else
157181 if (hasListeners) {
158182 [self sendEventWithName: @" errorEmitter" body: body];
@@ -165,7 +189,9 @@ - (void)didLogMessage:(NSString *)message {
165189 @" message" : message
166190 };
167191 #ifdef RCT_NEW_ARCH_ENABLED
168- [self emitLogEmitter: body];
192+ if (jsEventEmitterReady) {
193+ [self emitLogEmitter: body];
194+ }
169195 #else
170196 if (hasListeners) {
171197 [self sendEventWithName: @" logEmitter" body: body];
@@ -178,7 +204,9 @@ - (void)didUpdateToken:(RadarVerifiedLocationToken *)token {
178204 @" token" : [token dictionaryValue ]
179205 };
180206 #ifdef RCT_NEW_ARCH_ENABLED
181- [self emitTokenEmitter: body];
207+ if (jsEventEmitterReady) {
208+ [self emitTokenEmitter: body];
209+ }
182210 #else
183211 if (hasListeners) {
184212 [self sendEventWithName: @" tokenEmitter" body: body];
@@ -189,7 +217,7 @@ - (void)didUpdateToken:(RadarVerifiedLocationToken *)token {
189217RCT_EXPORT_METHOD (initialize:(NSString *)publishableKey fraud:(BOOL )fraud) {
190218 _publishableKey = publishableKey;
191219 [[NSUserDefaults standardUserDefaults ] setObject: @" ReactNative" forKey: @" radar-xPlatformSDKType" ];
192- [[NSUserDefaults standardUserDefaults ] setObject: @" 3.30 .0" forKey: @" radar-xPlatformSDKVersion" ];
220+ [[NSUserDefaults standardUserDefaults ] setObject: @" 3.31 .0" forKey: @" radar-xPlatformSDKVersion" ];
193221 [Radar initializeWithPublishableKey: publishableKey];
194222}
195223
0 commit comments