gpt4 book ai didi

react-native - react 原生推送通知中的预定推送通知操作 onClick/onPress 事件?

转载 作者:行者123 更新时间:2023-12-01 12:05:45 26 4
gpt4 key购买 nike

我正在使用这个包来实现本地推送通知:

https://github.com/zo0r/react-native-push-notification

我正在使用这样的操作按钮在我的通知中显示按钮以及文本和标题:

PushNotification.localNotification({
...
actions: '["Yes", "No"]'
})

我想知道当用户单击这些操作并且应用程序变得可见时如何调用函数?

我试过 PushNotification.configure在我的 componentDidMount我的主屏幕中的方法是这样的,但控制台中没有任何内容:
  PushNotification.configure({
// (required) Called when a remote or local notification is opened or received
onNotification: function(notification) {
console.log("NOTIFICATION:", notification);
if (notification.userInteraction) {
console.log("NOTIFICATION:");
}

// process the notification
}
});

最佳答案

我让它工作了。

在您的 App.js 中,您需要将 popInitialNotification 设置为 true。像这样的东西:

async componentDidMount() {
PushNotification.configure({
// (required) Called when a remote or local notification is opened or received
onNotification: function(notification) {
console.log("NOTIFICATION:", notification.action);
},

// IOS ONLY (optional): default: all - Permissions to register.
permissions: {
alert: true,
badge: true,
sound: true
},

// Should the initial notification be popped automatically
// default: true
popInitialNotification: true,

/**
* (optional) default: true
* - Specified if permissions (ios) and token (android and ios) will requested or not,
* - if not, you must call PushNotificationsHandler.requestPermissions() later
*/
requestPermissions: true
});
}

notification.action 会给你点击按钮的标签。

关于react-native - react 原生推送通知中的预定推送通知操作 onClick/onPress 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57179133/

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