【问题标题】:React native push notifcation to run a function on notification received反应本机推送通知以在收到通知时运行功能
【发布时间】:2016-11-08 15:46:11
【问题描述】:

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

还是应该用 Swift / Objective-C 来完成?

【问题讨论】:

    标签: javascript ios push-notification react-native apple-push-notifications


    【解决方案1】:

    绝对有可能!查看documentation for PushNotificationIOS

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

    您需要manually link the Library 并在您的AppDelegate.m 文件中添加侦听器。

    这也是假设您已经configured your APNs with Apple

    【讨论】:

    • Android 怎么样?我正在使用 react-native-firebase 的功能进行推送通知,并且没有在收到推送通知时触发的此类功能,特别是在应用程序被杀死/关闭时。
    • @Brad:嗨,布拉德,PushNotificationIOS 即使用户杀死了应用程序也能正常工作吗?还是只支持背景/前景?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-28
    • 1970-01-01
    相关资源
    最近更新 更多