我可以在操作按钮的同时生成通知,但是如何根据用户按下的按钮调用onpress事件呢?在这里,是的还是不是的,谢谢
从“react本机-推送-通知”导入PushNotification; 函数PushNotification.configure(){远程接收或打开时调用的函数({ // (必需)),或打开本地通知时调用的onNotification: console.log(通知){console.log(“通知:”,通知);//处理接收或打开远程时调用的通知// (必需),或打开本地通知( notification.finish();},// IOS (可选):默认:所有注册权限。权限:{警报:真,徽章:真,声音:真,},//如果初始通知被自动弹出//默认: true popInitialNotification: /** *(可选)默认值: true *-指定是否请求权限(ios)和令牌(android和ios),*-如果没有,稍后必须调用PushNotificationsHandler.requestPermissions() --如果您没有使用远程通知或没有安装Firebase,请使用以下命令:* requestPermissions: Platform.OS === 'ios‘*/ requestPermissions: true,requestPermissions: Platform.OS === 'ios',’content‘:1,});}函数给予通知(标题,消息){ PushNotification.localNotification({ channelId:‘通道’,消息:消息,// (必需)标题:标题,消息:消息,// (必需)操作:“是”,“否”};
发布于 2021-07-13 15:31:09
我从来没有直接使用过推送通知,对于我的通知,当您尝试记录Notifee时,我使用了包含这个"displayNotification“的displayNotification。我建议您尝试使用日志"PushNotification“来查找显示通知的函数。
发布于 2021-07-14 12:47:30
您可以按照以下代码设置该操作:
export const App = () => {
const [permissions, setPermissions] = useState({});
/**
* By calling this function, a notification with category `userAction` will have action buttons
*/
const setNotificationCategories = () => {
PushNotificationIOS.setNotificationCategories([
{
id: 'userAction',
actions: [
{id: 'open', title: 'Open', options: {foreground: true}},
{
id: 'ignore',
title: 'Desruptive',
options: {foreground: true, destructive: true},
},
{
id: 'text',
title: 'Text Input',
options: {foreground: true},
textInput: {buttonTitle: 'Send'},
},
],
},
]);
};
useEffect(() => {
PushNotificationIOS.addEventListener('notification', onRemoteNotification);
});
const onRemoteNotification = (notification) => {
const actionIdentifier = notification.getActionIdentifier();
if (actionIdentifier === 'open') {
// Perform action based on open action
}
if (actionIdentifier === 'text') {
// Text that of user input.
const userText = notification.getUserText();
// Perform action based on textinput action
}
};
};要了解更多信息,您可以访问图书馆的正式文档。
https://stackoverflow.com/questions/68365076
复制相似问题