Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when handling a dialog result #1417

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 29 additions & 23 deletions iOS_SDK/OneSignalSDK/Source/OneSignalDialogController.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ - (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;

[self displayDialog:request];
@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 +102,28 @@ - (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];
@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;

let nextDialog = self.queue.firstObject;

[self displayDialog:nextDialog];
}
});
}

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