首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在按下按钮时调用函数

如何在按下按钮时调用函数
EN

Stack Overflow用户
提问于 2021-07-13 15:11:53
回答 2查看 1.2K关注 0票数 0

我可以在操作按钮的同时生成通知,但是如何根据用户按下的按钮调用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:‘通道’,消息:消息,// (必需)标题:标题,消息:消息,// (必需)操作:“是”,“否”};

EN

回答 2

Stack Overflow用户

发布于 2021-07-13 15:31:09

我从来没有直接使用过推送通知,对于我的通知,当您尝试记录Notifee时,我使用了包含这个"displayNotification“的displayNotification。我建议您尝试使用日志"PushNotification“来查找显示通知的函数。

票数 0
EN

Stack Overflow用户

发布于 2021-07-14 12:47:30

您可以按照以下代码设置该操作:

代码语言:javascript
复制
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://github.com/zo0r/react-native-push-notification

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68365076

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档