Skip to content

Commit 64e2231

Browse files
committed
rm regiseruser queue to fix thread issues
* Removed background queue as some objects such as _outcomeEventsController are not thread safe resulting in some rare crashes due to dangling pointers. * We run on the main queue as registerUser has multiple entries points, so from other queues. - The main queue is where most of the OneSignal code that is not thread safe also runs.
1 parent 9aad5e5 commit 64e2231

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,12 +1610,6 @@ + (void)registerUserAfterDelay {
16101610
[OneSignalHelper performSelector:@selector(registerUser) onMainThreadOnObject:self withObject:nil afterDelay:reattemptRegistrationInterval];
16111611
}
16121612

1613-
static dispatch_queue_t serialQueue;
1614-
1615-
+ (dispatch_queue_t) getRegisterQueue {
1616-
return serialQueue;
1617-
}
1618-
16191613
+ (void)registerUser {
16201614
// return if the user has not granted privacy permissions
16211615
if ([self shouldLogMissingPrivacyConsentErrorWithMethodName:nil])
@@ -1631,13 +1625,12 @@ + (void)registerUser {
16311625

16321626
+(void)registerUserNow {
16331627
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"registerUserNow"];
1634-
1635-
if (!serialQueue)
1636-
serialQueue = dispatch_queue_create("com.onesignal.regiseruser", DISPATCH_QUEUE_SERIAL);
16371628

1638-
dispatch_async(serialQueue, ^{
1629+
// Run on the main queue as it is possible for this to be called from multiple queues.
1630+
// Also some of the code in the method is not thread safe such as _outcomeEventsController.
1631+
[OneSignalHelper dispatch_async_on_main_queue:^{
16391632
[self registerUserInternal];
1640-
});
1633+
}];
16411634
}
16421635

16431636
// We should delay registration if we are waiting on APNS

0 commit comments

Comments
 (0)