【问题标题】:How can i check push notification permission for both ios and android in react native?如何在 react native 中检查 ios 和 android 的推送通知权限?
【发布时间】:2019-04-21 14:54:06
【问题描述】:

我想检查 ios 和 android 的推送通知权限。我想看看用户是否从他的设备设置中关闭了推送通知权限。如果需要以本机编码,是否有任何插件或任何代码可以参考。

【问题讨论】:

    标签: javascript android ios react-native


    【解决方案1】:

    您可以查看react-native-permissionsnpm。集成后,您可以像这样使用它:

    componentDidMount() {
      Permissions.check('notification').then(response => {
        // Response is one of: 'authorized', 'denied', 'restricted', or 'undetermined'
        this.setState({ photoPermission: response })
      })
    }
    

    another library可以帮忙(我没用过)。

    建议here 也有本机实现。

    【讨论】:

    • 但使用 react-native-permission 的“通知”权限仅适用于 ios 而不适用于 android。
    • 这就是添加“另一个库”的原因。
    【解决方案2】:

    官方方式https://github.com/react-native-community/react-native-permissions#checknotifications

    import {requestNotifications} from 'react-native-permissions';
    
    requestNotifications(['alert', 'sound']).then(({status, settings}) => {
      // …
    });
    

    【讨论】:

    • 仅适用于 iOS
    【解决方案3】:

    安卓:

    实际上,推送通知权限位于普通类别权限中,如 INTERNET 权限而不是危险类别权限。

    您不必请求推送通知权限。

    更多细节在这里, https://stackoverflow.com/a/37294287/7188778

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多