react-native-notifications icon indicating copy to clipboard operation
react-native-notifications copied to clipboard

registerRemoteNotificationsRegistrationDenied being called even when "Allowed" clicked

Open hwhh opened this issue 1 year ago • 0 comments

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]);

hwhh avatar Jun 28 '24 20:06 hwhh