Problem:
Upgrading from SDK 5.0 to SDK 5.1 results in a deadlock if any Profile API calls are made from an Analytics Delegate Callback.
Example:
- (void)localyticsSessionWillOpen:(BOOL)isFirst isUpgrade:(BOOL)isUpgrade isResume:(BOOL)isResume; { NSDictionary *attributes = @{@"isFirstSession": isFirst ? @"true" : @"false", @"isFirstSessionAfterUpgrade": isUpgrade ? @"true" : @"false", @"willResumeOldSession": isResume ? @"true" : @"false"}; NSString *tag = [NSString stringWithFormat:@"delegate_event_willOpen_%lu",(unsigned long)self.count]; // The following line will result in a deadlock. [Localytics setValue:@"test" forProfileAttribute:@"testing"]; [Localytics tagEvent:tag attributes: attributes]; }
The Profile related calls will result in a deadlock when called from any of the following callback methods:
-
(void)localyticsSessionWillOpen:(BOOL)isFirst isUpgrade:(BOOL)isUpgrade isResume:(BOOL)isResume
-
(void)localyticsSessionWillOpen:(BOOL)isFirst isUpgrade:(BOOL)isUpgrade isResume:(BOOL)isResume
-
(void)localyticsDidTagEvent:(NSString *)event attributes:(NSDictionary *)attributes customerValueIncrease:(NSNumber *)customerValueIncrease
-
(void)localyticsSessionWillClose
Workaround:
- (void)localyticsSessionWillOpen:(BOOL)isFirst isUpgrade:(BOOL)isUpgrade isResume:(BOOL)isResume { NSDictionary *attributes = @{@"isFirstSession": isFirst ? @"true" : @"false", @"isFirstSessionAfterUpgrade": isUpgrade ? @"true" : @"false", @"willResumeOldSession": isResume ? @"true" : @"false"}; NSString *tag = [NSString stringWithFormat:@"delegate_event_willOpen_%lu",(unsigned long)self.count]; dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{ // Wrapping the call in dispatch_async prevents the deadlock. [Localytics setValue:@"test" forProfileAttribute:@"testing"]; }); [Localytics tagEvent:tag attributes: attributes]; }