React原生推送通知,在收到通知时运行一个函数

React native push notifcation to run a function on notification received

本文关键字:通知 运行 一个 函数 原生 React      更新时间:2023-09-26

当收到远程通知时,是否可以在javascript (react native)中运行函数?远程通知唤醒是否会在后台本地响应?

或者应该用Swift/Objective-C来完成?

绝对有可能!查看PushNotificationIOS的文档

componentWillMount() {
  PushNotificationIOS.addEventListener('notification', this._onRemoteNotification);
}
_onRemoteNotification(notification) {
  // handle the notification
}

您需要手动链接库并在AppDelegate.m文件中添加侦听器。

这也是假设你已经用Apple配置了apn。