1

根据 react-native 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];
 }
4

1 回答 1

1

你想知道是在 JS 端还是在 native 端。如果在本机端,请参阅此检测应用程序在 swift 中是在后台还是前台。在 JS 方面,您可以使用 react-native AppState api。https://facebook.github.io/react-native/docs/appstate

于 2019-03-07T16:06:59.617 回答