Skip to content

Commit b75c6ed

Browse files
authored
fix: avoid crash on iOS 14 when push comes on foreground (#234)
1 parent fce15a6 commit b75c6ed

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

ios/RNCPushNotificationIOS.m

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -429,14 +429,18 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
429429
[self sendEventWithName:@"remoteNotificationRegistrationError" body:errorDetails];
430430
}
431431

432-
RCT_EXPORT_METHOD(onFinishRemoteNotification:(NSString *)notificationId fetchResult:(UIBackgroundFetchResult)result) {
433-
RNCRemoteNotificationCallback completionHandler = self.remoteNotificationCallbacks[notificationId];
434-
if (!completionHandler) {
435-
RCTLogError(@"There is no completion handler with notification id: %@", notificationId);
436-
return;
437-
}
438-
completionHandler(result);
439-
[self.remoteNotificationCallbacks removeObjectForKey:notificationId];
432+
RCT_EXPORT_METHOD(onFinishRemoteNotification:(NSString *)notificationId fetchResult:(UIBackgroundFetchResult)result)
433+
{
434+
dispatch_async(dispatch_get_main_queue(), ^{
435+
RNCRemoteNotificationCallback completionHandler = self.remoteNotificationCallbacks[notificationId];
436+
if (!completionHandler) {
437+
RCTLogError(@"There is no completion handler with notification id: %@", notificationId);
438+
return;
439+
}
440+
441+
completionHandler(result);
442+
[self.remoteNotificationCallbacks removeObjectForKey:notificationId];
443+
});
440444
}
441445

442446
/**

0 commit comments

Comments
 (0)