Notifications - getAsync gives granted, Notifications.getExpoPushTokenAsync throws error.

Hi there,

I am using expo 30.0.0, The push notifications were working till version < 28.0.0, after upgrades to 30.0.0, here is the behavior…

async function registerForPushNotificationsAsync() {
    const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
    
    console_log("registerForPushNotificationsAsync....1");
    let finalStatus = existingStatus;
    alert("registerForPushNotificationsAsync1 "+finalStatus);
    // only ask if permissions have not already been determined, because
    // iOS won't necessarily prompt the user a second time.
    if (existingStatus !== 'granted') {
      // Android remote notification permissions are granted during the app
      // install, so this will only ask on iOS
      const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);

      finalStatus = status;
      alert("registerForPushNotificationsAsync2 "+finalStatus);
    }
    console_log("registerForPushNotificationsAsync....2");
  
    // Stop here if the user did not grant permissions
    if (finalStatus !== 'granted') {
        return new Promise((resolve,reject)=>{
            resolve(undefined);
        });
    }
    console_log("registerForPushNotificationsAsync....3");
    // Get the token that uniquely identifies this device
    try{
        let token = await Notifications.getExpoPushTokenAsync();
        console_log("registerForPushNotificationsAsync....4");
        token = (typeof token ==='string')?token:"no-token";
        // POST the token to your backend server from where you can retrieve it to send push notifications.
        return new Promise((resolve,reject)=>{
            console_log("registerForPushNotificationsAsync....5");
            resolve(token);
        });
    }catch(e){
        alert(e);
        return new Promise((resolve,reject)=>{
            resolve(undefined);
        });
    }
  }

The existingStatus coming as “granted” from getAsync call. there after Notifications.getExpoPushTokenAsync() throws exception “This app does not have permission to show notifications”.

Not sure about next steps to resolve. Am I doing something incorrect or something missing?

Please help.

thanks in advance.
-dp.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.