CatalystCode / react-native-azurenotificationhub

React Native module to support Azure Notification Hub push notifications on Android, iOS, and Windows.
MIT License
47 stars 75 forks source link

[iOS] crash right after calling requestPermissions #177

Closed khanhduy62 closed 3 years ago

khanhduy62 commented 3 years ago

Report

Environment

Issues and Steps to Reproduce

Expected Behavior

Actual Behavior

Link to Code

static async requestNotification(registeredSuccessHandler) {
    const _onRegistered = (deviceToken) => {
      this.registerNotification(deviceToken);
      // registeredSuccessHandler && registeredSuccessHandler(deviceToken);
    };

    const _onRegistrationError = (error) => {
      console.log('log--_onRegistrationError ', error);
    };

    const _onAzureNotificationHubRegistered = (registrationInfo) => {
      console.log('log--_onAzureNotificationHubRegistered ', registrationInfo);
    };

    const _onAzureNotificationHubRegistrationError = (error) => {
      console.log('log--_onAzureNotificationHubRegistrationError ', error);
    };

    const _onRemoteNotification = (remote) => {
      console.log('log--_onRemoteNotification ', remote);
    };

    const _onLocalNotification = (local) => {
      Alert.alert(
          'Local Notification Received',
          'Alert message: ' + local.getMessage(),
          [
            {
              text: 'Dismiss',
              onPress: () => {},
            },
          ],
      );
    };

    const callbackPermissions = (permissions) => {
      try {
        console.log('log--alert ', permissions?.alert);
        if (!permissions?.alert) {
          NotificationHub.requestPermissions()
              .then(console.log)
              .catch(console.warn);
        }
      } catch (error) {}
    };

    NotificationHub.addEventListener('register', _onRegistered);
    NotificationHub.addEventListener('registrationError', _onRegistrationError);
    NotificationHub.addEventListener(
        'registerAzureNotificationHub',
        _onAzureNotificationHubRegistered,
    );
    NotificationHub.addEventListener(
        'azureNotificationHubRegistrationError',
        _onAzureNotificationHubRegistrationError,
    );
    NotificationHub.addEventListener('notification', _onRemoteNotification);
    NotificationHub.addEventListener('localNotification', _onLocalNotification);

    NotificationHub.checkPermissions(callbackPermissions);
  }

  static registerNotification(deviceToken) {
    try {
      NotificationHub.register(deviceToken, {
        connectionString: AzureHub.connectionString,
        hubName: AzureHub.hubName,
        tags: ['']
      });
    } catch (error) {
      console.log(error);
    }
  }
potatoengineer commented 3 years ago

@khanhduy62 did you resolve this?

khanhduy62 commented 3 years ago

@khanhduy62 did you resolve this?

I did, so I think I should close this topic

potatoengineer commented 3 years ago

@khanhduy62 how did you resolve this? I'm stuck on the same issue.

yasaricli commented 1 year ago

+1, ping @phongcao