Skip to content

Commit 5ad4689

Browse files
committed
Fixed stability with alerts when enable visual logging level.
* Ensuring that debug alerts are run from the main thread when enabled. - This fixes errors with NSInternalInconsistencyException.
1 parent f680e20 commit 5ad4689

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

iOS_SDK/OneSignal/OneSignal.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,14 @@ void onesignal_Log(ONE_S_LOG_LEVEL logLevel, NSString* message) {
283283
NSLog(@"%@", [levelString stringByAppendingString:message]);
284284

285285
if (logLevel <= _visualLogLevel) {
286-
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:levelString
287-
message:message
288-
delegate:nil
289-
cancelButtonTitle:@"Close"
290-
otherButtonTitles:nil, nil];
291-
[alertView show];
286+
[OneSignalHelper runOnMainThread:^{
287+
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:levelString
288+
message:message
289+
delegate:nil
290+
cancelButtonTitle:@"Close"
291+
otherButtonTitles:nil, nil];
292+
[alertView show];
293+
}];
292294
}
293295
}
294296

iOS_SDK/OneSignal/OneSignalHelper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,8 @@
6868
+ (void)enqueueRequest:(NSURLRequest*)request onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock isSynchronous:(BOOL)isSynchronous;
6969
+ (void)handleJSONNSURLResponse:(NSURLResponse*) response data:(NSData*) data error:(NSError*) error onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock;
7070

71+
// Threading
72+
+ (void) runOnMainThread:(void(^)())block;
73+
7174
#pragma clang diagnostic pop
7275
@end

iOS_SDK/OneSignal/OneSignalHelper.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ + (void)addnotificationRequest:(NSDictionary *)data userInfo:(NSDictionary *)use
690690
if (!NSClassFromString(@"UNUserNotificationCenter"))
691691
return;
692692

693-
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
693+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
694694
[OneSignalHelper beginBackgroundMediaTask];
695695
id notificationRequest = [OneSignalHelper prepareUNNotificationRequest:data :userInfo];
696696
[[NSClassFromString(@"UNUserNotificationCenter") currentNotificationCenter] addNotificationRequest:notificationRequest withCompletionHandler:^(NSError * _Nullable error) {}];
@@ -846,6 +846,13 @@ + (void) displayWebView:(NSURL*)url {
846846

847847
}
848848

849+
+ (void) runOnMainThread:(void(^)())block {
850+
if ([NSThread isMainThread])
851+
block();
852+
else
853+
dispatch_sync(dispatch_get_main_queue(), block);
854+
}
855+
849856
#pragma clang diagnostic pop
850857
#pragma clang diagnostic pop
851858
#pragma clang diagnostic pop

0 commit comments

Comments
 (0)