Skip to content

Commit 9c0153a

Browse files
LinusUjkasten2
authored andcommitted
Fix access to currentUserNotificationSettings from non-ui threads
Fixes #826
1 parent 13b2715 commit 9c0153a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

ios/RCTOneSignal/RCTOneSignalEventEmitter.m

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,19 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
121121
return;
122122
}
123123

124-
NSUInteger types = 0;
125-
if ([UIApplication instancesRespondToSelector:@selector(currentUserNotificationSettings)]) {
126-
types = [RCTSharedApplication() currentUserNotificationSettings].types;
127-
} else {
124+
__block NSUInteger types = 0;
125+
126+
dispatch_sync(dispatch_get_main_queue(), ^{
127+
if ([UIApplication instancesRespondToSelector:@selector(currentUserNotificationSettings)]) {
128+
types = [RCTSharedApplication() currentUserNotificationSettings].types;
129+
} else {
128130

129131
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0
130-
types = [RCTSharedApplication() enabledRemoteNotificationTypes];
132+
types = [RCTSharedApplication() enabledRemoteNotificationTypes];
131133
#endif
132134

133-
}
135+
}
136+
});
134137

135138
callback(@[@{
136139
@"alert": @((types & UIUserNotificationTypeAlert) > 0),

0 commit comments

Comments
 (0)