0

如果用户在 Mac Catalyst 应用程序的系统偏好设置中关闭了“允许通知”切换,则不会调用回调 (...Registered...RegistrationFailed),因此应用程序不会收到有关远程通知是否有效的任何反馈。

一种解决方法是同时使用 react-native-permissions 并调用该模块的requestNotifications()函数。这真的是一种“解决方法”还是只是预期的用途?

(注意 -requestPermissions()无论我们是否存在手动调用,requestNotifications()都会调用本机代码中的函数,似乎该函数的错误在任何地方都没有得到尊重)

这是我们的用法(简化)

export const useRemoteNotifications = () => {
  useEffect(() => {
  
    // our workaround call to Permissions.requestNotifications().then(whatever) happens here

    const registeredSub = Notifications.events().registerRemoteNotificationsRegistered(
      // register the device with our API
    );
  
    const registrationFailedSub = Notifications.events().registerRemoteNotificationsRegistrationFailed(
      // alert the user the app doesn't work great without push notifications
    );
    return () => {
      registeredSub.remove();
      registrationFailedSub.remove();
    };
  }
};
4

0 回答 0