Permission dialog not showing on iOS for notifications

When a user visits the dashboard of my app I would like to show a prompt asking for permission for push notifications. I assumed the following code would do just that, what I find instead is that the dialog asking for permission never shows and the status is resolved as ‘granted’.

Is there some setting (maybe in app.json) that I need to set to show the permission dialog?

    if (existingStatus !== "granted") {
      const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
      finalStatus = status;
      expoToken = await Notifications.getExpoPushTokenAsync();
      user.pushNotificationTokens = user.pushNotificationTokens ? user.pushNotificationTokens : []
      user.pushNotificationTokens = [...user.pushNotificationTokens, expoToken];

      const savedUser = await this.saveAthlete(user)

Thank you for any insight.


From the Permissions docs:

Manually testing permissions

Often you want to be able to test what happens when you reject a permission to ensure that it has the desired behavior. An operating-system level restriction on both iOS and Android prohibits an app from asking for the same permission more than once (you can imagine how this could be annoying for the user to be repeatedly prompted for permissions). So in order to test different flows involving permissions, you may need to uninstall and reinstall the Expo app. In the simulator this is as easy as deleting the app and expo-cli will automatically install it again next time you launch the project from it.

Awesome, this makes sense. Thank you, Marcus!

1 Like