【问题标题】:React Native Push Notifications not appearing in settingsReact Native Push Notifications 未出现在设置中
【发布时间】:2020-05-22 15:55:05
【问题描述】:

我是原生反应新手,我正在尝试通过 iOS 设置推送通知。

我已安装 pushNotificationios 并按照给出的说明进行操作。我还注册了 Apple Developer。

当我运行我的应用程序时,推送通知似乎不起作用。当我进入我的 iPhone 设置并点击应用时,它不会显示通知。

这是我的代码

import PushNotificationIOS from '@react-native-community/push-notification-ios';
import PushNotification from "react-native-push-notification";

const configure = () => {
 PushNotification.configure({

   onRegister: (token) => {
    console.log('TOKEN:', token);
     //process token
   },

   onNotification: (notification) => {
     // process the notification
     console.log("NOTIFICATION:", notification);
     // required on iOS only
     notification.finish(PushNotificationIOS.FetchResult.NoData);
   },

   permissions: {
     alert: true,
     badge: true,
     sound: true
   },
  
   popInitialNotification: true,
   requestPermissions: true,

 });
};


 export {
    configure,
   };

【问题讨论】:

  • 这是在模拟器上还是在实际设备上
  • 我都试过了
  • 您是否添加了“推送通知”功能(xcode->target->签名和功能)?
  • 您在 iphone 上收到任何权限框了吗?
  • 你在任何文件中调用configure()函数吗?

标签: ios react-native push-notification


【解决方案1】:

我的包有权限问题

可以使用react-native-permissions包获取通知权限

import {requestNotifications} from 'react-native-permissions';

requestNotifications(['alert', 'sound']).then(({status, settings}) => {
  // …
});

【讨论】:

    【解决方案2】:
    1. 检查您的 XCode 通知设置

    2. 尝试在您的 FirstPage 中请求许可,如下所示。不是索引。

    const MainPage = {} => {
      useEffect(() => {
        PushNotificationIOS.requestPermissions(['alert', 'badge', 'sound']);
      }, [])
    }
    

    iOS:如果用户没有看到请求权限弹出窗口,则用户无法在首选项中看到警报选项。

    Android:不需要请求许可。

    【讨论】:

    • @becky 不用担心。几乎一样。
    • 不变违规:无效的钩子调用。 Hook 只能在函数组件的主体内部调用。
    • 如果你使用类组件,只需使用componentDidMount。重点是打电话给PushNotificationIOS.requestPermissions
    【解决方案3】:

    我不知道你的包名是否有特殊字符,但我和你有同样的问题,为了解决我需要去xCode,构建设置(项目)并更改产品名称,因为我的产品名称有口音(如“ó”),而那不是英文名称。可笑但解决了

    【讨论】:

      猜你喜欢
      • 2021-03-06
      • 1970-01-01
      • 2022-10-01
      • 2020-07-09
      • 1970-01-01
      • 2023-01-09
      • 1970-01-01
      • 2022-01-08
      • 2021-05-18
      相关资源
      最近更新 更多