iOS接收推送通知';s仅在关闭/重新打开应用程序之后

iOS接收推送通知';s仅在关闭/重新打开应用程序之后,ios,react-native,push-notification,firebase-cloud-messaging,Ios,React Native,Push Notification,Firebase Cloud Messaging,我最近在ios推送通知中遇到了这个问题,在第一次发布时安装应用程序后,推送通知没有立即收到。我必须关闭应用程序,从最近的应用程序中删除并重新打开它,然后推送通知开始工作。知道为什么会发生这种情况,以及修复它的方法吗 我试着关注这两个github问题,但都没有帮助 下面是我正在使用的代码和版本: "@react-native-community/push-notification-ios": "^1.4.1", "@react-native-fi

我最近在ios推送通知中遇到了这个问题,在第一次发布时安装应用程序后,推送通知没有立即收到。我必须关闭应用程序,从最近的应用程序中删除并重新打开它,然后推送通知开始工作。知道为什么会发生这种情况,以及修复它的方法吗

我试着关注这两个github问题,但都没有帮助

下面是我正在使用的代码和版本:

"@react-native-community/push-notification-ios": "^1.4.1",
"@react-native-firebase/app": "^8.4.1",
"@react-native-firebase/messaging": "^7.8.3",
"react-native-push-notification": "^5.0.1",
AppDelegate.m

我有一个内置的
did完成启动选项

UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;
  
  if ([UNUserNotificationCenter class] != nil) {
      // iOS 10 or later
      // For iOS 10 display notification (sent via APNS)
      [UNUserNotificationCenter currentNotificationCenter].delegate = self;
      UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert |
      UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
      [FIRMessaging messaging].delegate = self;
      [[UNUserNotificationCenter currentNotificationCenter]
       requestAuthorizationWithOptions:authOptions
       completionHandler:^(BOOL granted, NSError * _Nullable error) {
         if (error) { NSLog(@"%@", error); }
       }];
    } else {
      // iOS 10 notifications aren't available; fall back to iOS 8-9 notifications.
      UIUserNotificationType allNotificationTypes =
      (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
      UIUserNotificationSettings *settings =
      [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
      [application registerUserNotificationSettings:settings];
    }
  [application registerForRemoteNotifications];
  
  
  return YES;
这是根据文件写的吗

// Required to register for notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
 [RNCPushNotificationIOS didRegisterUserNotificationSettings:notificationSettings];
}
// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
 [RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
// Required for the notification event. You must call the completion handler after handling the remote notification.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
  
  [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
// Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
 [RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error];
}
// IOS 10+ Required for localNotification event
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
         withCompletionHandler:(void (^)(void))completionHandler
{
  [RNCPushNotificationIOS didReceiveNotificationResponse:response];
  completionHandler();
}
// IOS 4-10 Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
 [RNCPushNotificationIOS didReceiveLocalNotification:notification];
}

-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
 completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}