diff --git a/lib/ios/RNNotificationCenterMulticast.m b/lib/ios/RNNotificationCenterMulticast.m index c1c6add..1cf2fcb 100644 --- a/lib/ios/RNNotificationCenterMulticast.m +++ b/lib/ios/RNNotificationCenterMulticast.m @@ -22,20 +22,53 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { - for (id delegate in delegates) { - if ([delegate respondsToSelector:@selector(userNotificationCenter:willPresentNotification:withCompletionHandler:)]) { - [delegate userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler]; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + dispatch_group_t completionGroup = dispatch_group_create(); + + __block UNNotificationPresentationOptions allOptions = UNNotificationPresentationOptionNone; + void (^myCompletion)(UNNotificationPresentationOptions); + myCompletion = ^(UNNotificationPresentationOptions options){ + allOptions |= options; + dispatch_group_leave(completionGroup); + }; + + for (id delegate in delegates) { + if ([delegate respondsToSelector:@selector(userNotificationCenter:willPresentNotification:withCompletionHandler:)]) { + dispatch_group_enter(completionGroup); + [delegate userNotificationCenter:center willPresentNotification:notification withCompletionHandler:myCompletion]; + } } - } + + dispatch_group_wait(completionGroup, dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC)); + + dispatch_async(dispatch_get_main_queue(), ^{ + completionHandler(allOptions); + }); + }); } - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler { - for (id delegate in delegates) { - if ([delegate respondsToSelector:@selector(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:)]) { - [delegate userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler]; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + dispatch_group_t completionGroup = dispatch_group_create(); + + void (^myCompletion)(void) = ^{ + dispatch_group_leave(completionGroup); + }; + + for (id delegate in delegates) { + if ([delegate respondsToSelector:@selector(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:)]) { + dispatch_group_enter(completionGroup); + [delegate userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:myCompletion]; + } } - } + + dispatch_group_wait(completionGroup, dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC)); + + dispatch_async(dispatch_get_main_queue(), ^{ + completionHandler(); + }); + }); } - (void)userNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(nullable UNNotification *)notification