From 892272142815e61e0d10343aa55d69c1c7e73caa Mon Sep 17 00:00:00 2001 From: jennmueng Date: Wed, 17 Mar 2021 16:04:31 +0700 Subject: [PATCH] fix: Support setting user as null on iOS native bridge --- src/ios/SentryCordova.m | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ios/SentryCordova.m b/src/ios/SentryCordova.m index 621dc69..b333296 100755 --- a/src/ios/SentryCordova.m +++ b/src/ios/SentryCordova.m @@ -182,19 +182,23 @@ - (void)setUser:(CDVInvokedUrlCommand *)command { NSDictionary *user = [command.arguments objectAtIndex:0]; NSDictionary *otherUserKeys = [command.arguments objectAtIndex:1]; + bool userIsNull = (nil == user || [user isEqual:[NSNull null]]); + bool otherUserKeysIsNull = + (nil == otherUserKeys || [otherUserKeys isEqual:[NSNull null]]); + [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { - if (nil == user && nil == otherUserKeys) { + if (userIsNull && otherUserKeysIsNull) { [scope setUser:nil]; } else { SentryUser *userInstance = [[SentryUser alloc] init]; - if (nil != user) { + if (!userIsNull) { [userInstance setUserId:user[@"id"]]; [userInstance setEmail:user[@"email"]]; [userInstance setUsername:user[@"username"]]; } - if (nil != otherUserKeys) { + if (!otherUserKeysIsNull) { [userInstance setData:otherUserKeys]; }