la-haus / flutter-segment

Segment.io library for flutter
MIT License
22 stars 139 forks source link

[iOS] Fix userId nil #28

Closed zenled closed 2 years ago

zenled commented 2 years ago

Fixes a bug on iOS, where Segment would not report correctly when calling identify with userId: null.

Explanation: in iOS when userId is obtained from arguments it might be NSNull, but the Segment library expects it to be nil. Added a line to convert userId from NSNull to nil.

Related issue Identify userId is optional but the implementation does not reflect this.

danielgomezrico commented 2 years ago

@zenled thanks for the contribution, I have a question, when you say would not report correctly how does it report it? Can you show some logs or events created in segment to understand better the issue?

zenled commented 2 years ago

To explain the problem a bit further:

// Dart
await Segment.identify(userId: null, traits: {'firstName': 'John'});

Of the iOS side after the line NSString *userId = call.arguments[@"userId"]; the userId is NSNull. The problem is that the identify method expects it to be NSString or nil.

My fix converts the NSNull to nil.

Without the fix, the native Segment library throws (exception NSException * @"-[NSNull length]: unrecognized selector sent to instance...).