Skip to content

Commit

Permalink
fix(analytics, ios): Convert NSNull values to nil in order to correct…
Browse files Browse the repository at this point in the history
…ly remove user properties

Closes #4931
  • Loading branch information
bonesyblue authored and mikehardy committed Jan 10, 2022
1 parent f6b9053 commit dbc79c3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/analytics/ios/RNFBAnalytics/RNFBAnalyticsModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ - (dispatch_queue_t)methodQueue {
: (RCTPromiseResolveBlock)resolve rejecter
: (RCTPromiseRejectBlock)reject) {
@try {
[FIRAnalytics setUserID:id];
[FIRAnalytics setUserID:[self convertNSNullToNil:id]];
} @catch (NSException *exception) {
return [RNFBSharedUtils rejectPromiseWithExceptionDict:reject exception:exception];
}
Expand All @@ -79,7 +79,7 @@ - (dispatch_queue_t)methodQueue {
: (RCTPromiseResolveBlock)resolve rejecter
: (RCTPromiseRejectBlock)reject) {
@try {
[FIRAnalytics setUserPropertyString:value forName:name];
[FIRAnalytics setUserPropertyString:[self convertNSNullToNil:value] forName:name];
} @catch (NSException *exception) {
return [RNFBSharedUtils rejectPromiseWithExceptionDict:reject exception:exception];
}
Expand All @@ -92,7 +92,7 @@ - (dispatch_queue_t)methodQueue {
: (RCTPromiseRejectBlock)reject) {
@try {
[properties enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) {
[FIRAnalytics setUserPropertyString:value forName:key];
[FIRAnalytics setUserPropertyString:[self convertNSNullToNil:value] forName:key];
}];
} @catch (NSException *exception) {
return [RNFBSharedUtils rejectPromiseWithExceptionDict:reject exception:exception];
Expand Down Expand Up @@ -162,4 +162,10 @@ - (NSDictionary *)cleanJavascriptParams:(NSDictionary *)params {
return [newParams copy];
}

/// Converts null values received over the bridge from NSNull to nil
/// @param value Nullable string value
- (NSString *)convertNSNullToNil:(NSString *)value {
return [value isEqual:[NSNull null]] ? nil : value;
}

@end

1 comment on commit dbc79c3

@vercel
Copy link

@vercel vercel bot commented on dbc79c3 Jan 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.