From 1e3647d0d8516c7938c9705243e0dd3865e1ac79 Mon Sep 17 00:00:00 2001 From: Kyle Kurz Date: Thu, 19 Mar 2020 07:56:56 -0700 Subject: [PATCH] Use main thread 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. --- ios/RNCPushNotificationIOS.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ios/RNCPushNotificationIOS.m b/ios/RNCPushNotificationIOS.m index be7176186..0fe264477 100644 --- a/ios/RNCPushNotificationIOS.m +++ b/ios/RNCPushNotificationIOS.m @@ -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)); }];