Skip to content

Commit

Permalink
Merge pull request #1417 from OneSignal/fix/delay_result_crash
Browse files Browse the repository at this point in the history
Fix crash when handling a dialog result
  • Loading branch information
emawby committed Apr 29, 2024
2 parents 5626c7f + 790b776 commit 867a449
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions iOS_SDK/OneSignalSDK/Source/OneSignalDialogController.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ - (void)presentDialogWithTitle:(NSString * _Nonnull)title withMessage:(NSString
//ensure this UI code executes on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
let request = [[OSDialogRequest alloc] initWithTitle:title withMessage:message withActionTitles:actionTitles withCancelTitle:cancelTitle withCompletion:completion];

[self.queue addObject:request];

//check if already presenting a different dialog
//if so, we shouldn't present on top of existing dialog
if (self.queue.count > 1)
return;

@synchronized (self.queue) {
[self.queue addObject:request];
//check if already presenting a different dialog
//if so, we shouldn't present on top of existing dialog
if (self.queue.count > 1)
return;
}
[self displayDialog:request];
});
}
Expand Down Expand Up @@ -101,23 +101,30 @@ - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)butto

- (void)delayResult:(int)result {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
let currentDialog = self.queue.firstObject;

if (currentDialog.completion)
currentDialog.completion(result);

[self.queue removeObjectAtIndex:0];

//check if no more dialogs left to display in queue
if (self.queue.count == 0)
return;

let nextDialog = self.queue.firstObject;

[self displayDialog:nextDialog];
OSDialogRequest *nextDialog = nil;
@synchronized (self.queue) {
if (self.queue.count > 0) {
let currentDialog = self.queue.firstObject;

if (currentDialog.completion)
currentDialog.completion(result);

[self.queue removeObjectAtIndex:0];
}

//check if no more dialogs left to display in queue
if (self.queue.count == 0)
return;

nextDialog = self.queue.firstObject;
}
if (nextDialog != nil) {
[self displayDialog:nextDialog];
}
});
}

// Unused. Currently only referenced in player model unit tests
- (void)clearQueue {
self.queue = [NSMutableArray new];
}
Expand Down

0 comments on commit 867a449

Please sign in to comment.