wix / react-native-notifications

React Native Notifications
MIT License
3.25k stars 764 forks source link

registerRemoteNotificationsRegistrationDenied being called even when "Allowed" clicked #1044

Open hwhh opened 4 months ago

hwhh commented 4 months ago

Hi,

I am wondering if I am missing something, but whenever I click "Allow" on the IOS notifications popup the registerRemoteNotificationsRegistrationDenied callback is fired?

useEffect(() => {
    const listeners: EmitterSubscription[] = [];
    if (currentUser && !currentUserLoading && !notificationsRequested) {
      setNotificationLoading(true);
      Notifications.isRegisteredForRemoteNotifications().then(enabled => {
        if (enabled) {
          setNotificationsRequested(true);
        }
        setNotificationLoading(false);
      });
      const allowedListener =
        Notifications.events().registerRemoteNotificationsRegistered(event => {
          console.log('registerRemoteNotificationsRegistered');
          checkNotificationConfig(currentUser, event).then(() => {
            setNotificationsRequested(true);
            setNotificationLoading(false);
          });
        });
      const errorListener =
        Notifications.events().registerRemoteNotificationsRegistrationFailed(_ => {
          console.log('registerRemoteNotificationsRegistrationFailed');
          setNotificationsRequested(true);
          setTimeout(() => setNotificationLoading(false), 100);
        });
      const declinedListener =
        Notifications.events().registerRemoteNotificationsRegistrationDenied(() => {
          console.log('registerRemoteNotificationsRegistrationDenied');
          setNotificationsRequested(true);
          setNotificationLoading(false);
        });

      listeners.push(...[allowedListener, errorListener, declinedListener]);
    } else {
      setNotificationLoading(false);
    }
    return () => {
      listeners.forEach(listener => listener?.remove());
    };
  }, [checkNotificationConfig, currentUser, currentUserLoading, notificationsRequested]);