Skip to content

Commit

Permalink
chore: Use main thread for requesting notification permissions. (#90)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kylekurz authored Apr 1, 2020
1 parent 99a0228 commit bf19cc1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ios/RNCPushNotificationIOS.m
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
if (error != NULL) {
reject(@"-1", @"Error - Push authorization request failed.", error);
} else {
[RCTSharedApplication() registerForRemoteNotifications];
dispatch_async(dispatch_get_main_queue(), ^(void){
[RCTSharedApplication() registerForRemoteNotifications];
});
[UNUserNotificationCenter.currentNotificationCenter getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
resolve(RCTPromiseResolveValueForUNNotificationSettings(settings));
}];
Expand Down

0 comments on commit bf19cc1

Please sign in to comment.