Notifications.getExpoPushTokenAsync returns "Error: This app does not have permission to show notifications"


#1

I’m not sure when it started, but sometime over the last month or two some fresh installs on iOS are hanging on getPushTokenAsync(). It looks like it’s because getAsync incorrectly returns “granted” when it’s not granted on a fresh installation.

This is happening on an iPad 2 I’m testing, both with a fresh standalone IPA installation and with a completely fresh install of the Expo client (so no permissions granted yet). Latest Expo client version today.

My app calls getPushTokenAsync() below. Somehow getAsync(Permissions.NOTIFICATIONS) returns “granted”! Then lower down the function, Notifications.getExpoPushTokenAsync() errors with “Error: This app does not have permission to show notifications”.

Anyone else seen this?

export default (async function getPushTokenAsync() {
  // Remote notifications do not work in simulators, only on device
  if (!Constants.isDevice) {
    return null;
  }

  // Get current notification permissions status
  const { status: existingStatus } = await Permissions.getAsync(
    Permissions.NOTIFICATIONS
  );
  let finalStatus = existingStatus;

  // 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;
  }

  // Stop here if the user did not grant permissions
  if (finalStatus !== "granted") {
    return null;
  }

  // Get the token that uniquely identifies this device
  let token = await Notifications.getExpoPushTokenAsync();

  // Return the token
  return token;
});

#2

This seems like a bug; until it’s fixed I recommend using a try-catch around your getExpoPushTokenAsync() call and testing for that error.


#3

Thanks, yes it must be a bug.

Quite widespread as well, I’ve just been rejected by Apple because it happened during their review, and my beta testers are reporting it.

I can put it in a try-catch but that means push notifications are no longer working on iOS.

Thanks


#4

Hey there, we’ve just landed a fix for this internally which will go out with our next release. Thanks for the report.

Edit: We’re also tracking the issue here: https://github.com/expo/expo/issues/1960


#5

Brilliant thanks! Will it be in the next release of the SDK (29) or next release of some other package?


#6

When we release SDK 29, the fix will be included in SDK 29 and will also be backported to our older SDKs at the same time. The fix will affect both Expo Client as well as apps created with exp build. This is our next planned release of any kind.


closed #7

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