Skip to content

Commit bf19cc1

Browse files
authored
chore: Use main thread for requesting notification permissions. (#90)
iOS throws a warning that registerForRemoteNotifications must be called from the main thread only, this just wraps that call in a block to ensure it always runs there, regardless of how the containing function is called.
1 parent 99a0228 commit bf19cc1

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ios/RNCPushNotificationIOS.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
315315
if (error != NULL) {
316316
reject(@"-1", @"Error - Push authorization request failed.", error);
317317
} else {
318-
[RCTSharedApplication() registerForRemoteNotifications];
318+
dispatch_async(dispatch_get_main_queue(), ^(void){
319+
[RCTSharedApplication() registerForRemoteNotifications];
320+
});
319321
[UNUserNotificationCenter.currentNotificationCenter getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
320322
resolve(RCTPromiseResolveValueForUNNotificationSettings(settings));
321323
}];

0 commit comments

Comments
 (0)