Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

registerRemoteNotificationsRegistrationDenied being called even when "Allowed" clicked #1044

Open
hwhh opened this issue Jun 28, 2024 · 0 comments

Comments

@hwhh
Copy link

hwhh commented Jun 28, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant