当app被杀死时,在推送通知后执行操作:react-native,IOS

问题描述 投票:0回答:1

致力于IOS反应原生项目。

当应用程序为DEAD并收到推送通知时 -

我希望应用程序根据通知的有效负载导航到另一个页面。当应用程序处于前台或后台时 - 一切正常。当应用程序被杀死时 - 应用程序就会自行打开。

下面添加的是我的Appdelegate.m代码。我正在捕获通知并将其记录到控制台,但我不知道如何将其发送到react-native。

使用RN 0.46

世博会19(与ExpoKit分开)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    _window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    _window.backgroundColor = [UIColor whiteColor];
    [[ExpoKit sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
    _rootViewController = [ExpoKit sharedInstance].rootViewController;
    _window.rootViewController = _rootViewController;

    [_rootViewController loadReactApplication];
    [_window makeKeyAndVisible];


    if ([launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {
          NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
          if (notification) {
              //logs the notification's payload
              NSLog(@"app recieved notification from remote%@",notification);
          } else {
              NSLog(@"app did not recieve notification");
          }

    }

    return YES;
}

https://jsfiddle.net/nirbenya/pxojj7qv/

ios objective-c react-native react-native-ios expo
1个回答
0
投票

要实现此类行为,您需要为您的应用程序实现某种deep linking。这样,您可以在您的react-native应用程序中侦听有效负载并导航到正确的屏幕。 react-navigationreact-native-navigation有自己的深层链接实现。

来自react-native docs,

处理深层链接

如果您的应用是从注册到您应用的外部网址启动的,则您可以从所需的任何组件访问和处理该应用

componentDidMount() {
  Linking.getInitialURL().then((url) => {
    if (url) {
      console.log('Initial url is: ' + url);
    }
  }).catch(err => console.error('An error occurred', err));
}
© www.soinside.com 2019 - 2024. All rights reserved.