react-native PushNotificationIOS - 我如何确定通知处理程序是从前台还是后台调用的

react-native PushNotificationIOS - how do I figure out if the notification handler was called from the foreground or the background

根据本机 PushNotificationIOS 文档(未在插件中使用),我的 AppDelegate 中有以下代码,对 didReceiveRemoteNotification 稍作调整,以便它处理前台和后台的通知,但是,我不能'不知道它是从哪里处理的,我的处理程序需要知道,因为它做不同的事情。

关于如何获取此信息的任何想法?

// Required to register for notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
 {
  [RCTPushNotificationManager didRegisterUserNotificationSettings:notificationSettings];
 }
 // Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
 {
  [RCTPushNotificationManager 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
 {
  [RCTPushNotificationManager didReceiveRemoteNotification:userInfo];
  completionHandler(UIBackgroundFetchResultNewData);
 }
 // Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
 {
  [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error];
 }
 // Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
 {
  [RCTPushNotificationManager didReceiveLocalNotification:notification];
 }

你想知道是JS端还是native端。如果在原生端,参考这个. In JS side you can use react-native AppState api. https://facebook.github.io/react-native/docs/appstate