gpt4 book ai didi

android - 在 React Native 中推送通知

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:19:59 26 4
gpt4 key购买 nike

我在“react-native-push-notification”库的帮助下将推送通知集成到 React Native 中。推送来自节点 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com