Expo not returning token with getExpoPushTokenAsync on iOS Expo Client

Hi! I am new to Expo and React Native in general. We are building an app for college campuses. I am trying to implement push notification for an app. The problem I am running in to is that after going through the starter code in Expo Docs for notifications and running the app on the Expo Client for iOS I was not able to generate the token and more surprisingly I was not logging any errors. I even tried try/catch syntax for any errors but still didn’t get any errors. getExpoPushTokenAsync isn’t returning any token. This is my code:

    async sendPushNotifToken() {
        const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS)
        console.log(existingStatus)
        let finalStatus = existingStatus
        if (existingStatus !== 'granted') {
             const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS)
             finalStatus = status
         }
         if (finalStatus !== 'granted') {
             return
         }
         console.log("Fetching token")
        let token = await Notifications.getExpoPushTokenAsync()
        console.log(token) // Not able to run this line to run. Code seems to be stuck on the above line.
  }

Any help is much appreciated!

Update: I am on the latest version of the Expo Client App for iOS. In fact I installed and uninstalled the app multiple times to figure out the issue myself

2 Likes

Hey @miraj98!

Are you running this on a simulator? Simulators cannot receive push notifications. To test them out you will need to use a real-life device.

You can read more about that in our docs.

1 Like

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