Undetermined status on external iOS device push notifications

#1

Hello, I am testing on an external Iphone since I know push notifs do not work on simulator. My Expo tokens weren’t being sent to my Firebase database so I dug into the code and discovered that my status variable from async call Permissions.askAsync(Permissions.NOTIFICATIONS) returns as undetermined. All the responses I’ve seen on this forum relate to this issue being from a simulator so I’m confused as to why this is happening.

  • The first time I opened the app on iphone I allowed push notifications. Just to check here is a screenshot of the notifications panel showing they are on:

Here is the corresponding code I am using essentially straight from docs:

import { Font, AppLoading, Permissions, Notifications } from 'expo';

and the function called on componentDidMount()

    registerForPushNotificationsAsync = async (user) => {
    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);
        console.log(status);
        finalStatus = status;
      }
      
      // Stop here if the user did not grant permissions
      if (finalStatus !== 'granted') {
        
        return;
      }
      
      // Get the token that uniquely identifies this device
      let token = await Notifications.getExpoPushTokenAsync();
      alert(token);
      var updates = {}
      updates['/expoToken'] = token;
      database.ref('users').child(user.uid).update(updates)
}

As you can see, I’ve been console logging the status variable and it shows undetermined at that point. How else can I help debug this issue? Thanks!

#2

This might just be a bug. What does getAsync return?

#3

@ide so I put a console.log(status); on the line just under:

const { status: existingStatus } = await Permissions.getAsync( Permissions.NOTIFICATIONS );

and I don’t get any response. Is there a better way to check the async response maybe console.log isn’t good for that?

#4

Your code might be simply failing — your declared variable is existingStatus.

#5

@ide i tried logging existingStatus and that returns undetermined but status doesn’t. Code is identical to the docs so I’m not quite sure what is messed up.

#6

@ide also I don’t know if this is relevant but checking my expo node module’s Permissions.js looks like this:

the errors state that type aliases can only be used in a ts file? Is that just an unnecessary error?

#7

@ide also here is the entire object that is returned, as you can see, notifications for alert, badge, and sound are all true, yet the status remains undetermined…

closed #8

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