android - React Native 中的推送通知

标签 android ios firebase react-native push-notification

我正在“react-native-push-notification”库的帮助下将推送通知集成到react native中。推送来自 Node js(后端)。 我在 Android 和 IOS 环境中都成功推送。

现在我有两个问题 1)在ios中,当我收到推送时,通知负载“userInteraction”中有一个参数。该参数用于确定用户是否点击了通知。现在它在 android 中工作正常,但在 ios 中这总是错误的。 2)我想在推送通知中设置自定义图像,该图像来自推送。

我正在使用“https://www.npmjs.com/package/react-native-push-notification ”这个库。

我已经尝试过这段代码:-

  export function setupPushNotification(handleNotification) {
    PushNotification.configure({

    onRegister: function (token) {

        if (Platform.OS == 'ios') {
            firebase.messaging().getToken().then((token) => {
                alert(JSON.stringify(token))
                requestaddAuthToke(token)
            .then((data) => {
                console.log("hello2 " + JSON.stringify(data))
            })
            .catch((error) => {
                console.log("hello3 " + JSON.stringify(error.message));
            })
            });
        }
        else {
            console.log("hello2 " + JSON.stringify(token.token))
            requestaddAuthToke(token.token)
            .then((data) => {
                console.log("hello2 " + JSON.stringify(data))
            })
            .catch((error) => {
                console.log("hello3 " + JSON.stringify(error.message));
            })
        }
    },

    onNotification: function (notification) {
        const clicked = notification.userInteraction;
        if (clicked)
            handleNotification(notification.episodeCode)

        if (Platform.OS == 'ios')
            notification.finish(PushNotificationIOS.FetchResult.NoData);

    },

    senderID: "529815244511",
    permissions: {
        alert: true,
        badge: true,
        sound: true
    },



    popInitialNotification: true,
    requestPermissions: true,


 })

  return PushNotification
}

任何类型的帮助将不胜感激。

最佳答案

您同时使用react-native-push-notification和react-native-one-signal。唯一的问题是仅在 iOS 中点击本地通知时不会调用 onNotification。

解决方案:

https://github.com/zo0r/react-native-push-notification/issues/919#issuecomment-439373380

关于android - React Native 中的推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57657528/

相关文章:

iphone - 如何检测 UIImageView 的宽度和高度

firebase - 如何为不同的 Firebase 托管项目设置域及其子域

Android 通知内容文本不会显示在 OS 4.4.4 Kitkat 上,但会显示在 OS 5.0 Lollipop 上

android - “kernel-qemu” 丢失。 - AVD 经理

ios - 如何实现用于大量文本输入的 UITextView 屏幕

android - 使用 kivy 在 Android 和 IOS 中播放音频(mp3)

android - Unity3D - 多个 dex 文件定义了为 android (Firebase) 构建时的异常

firebase - 如何从异步函数中正确获取字符串?

android - 在 Android 中设计 ListView

安卓用户界面改进