Does Expo generate production keys for push notifications?

I want to test my push notifications in test flight but after following the documentation on expo, my finalstatus is always undetermined. Note this only happens when I test on a real device using testflight. When testing in development push notifications work fine. After doing some research, it appears that I need to manually generate a production push notification key from apple connect and then manually upload it to expo. However, I have only seen this advice in the forums and nothing regarding this in expo’s official documentation. I would imagine that if you choose all the ‘let expo do it’ options when running expo build:ios, that it would generate production ready push notification keys, but I want to confirm here that this is not the case and that they need to be generated manually (and if so I would recommend updating the docs to state as much) . Below is the code I am using to generate the token (This is pulled pretty much verbatim from expo docs).


async function registerForPushNotificationsAsync() {
  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 'not granted' + finalStatus;  //final status is always undefined only in testflight, works fine in development.
  }

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

  return token

}

Hey @shomari,

You should be presented the option to have your PNK automatically generated and linked for you during the expo build:ios flow. Can you let me know what version of expo-cli you are using?

Cheers,
Adam

@adamjnav I have not ever received an option about having PNK automatically generated. I am using expo-cli v 3.0.2

$ expo-cli -V
3.0.2

This is the output when I run expo build:ios -clear-credentials. (I replaced some sensitive information). Nothing about PNK ever comes up

$ expo build:ios --clear-credentials
Checking if there is a build in progress...

Removed existing credentials from expo servers
Please enter your Apple Developer Program account credentials. These credentials are needed to manage certificates, keys and provisioning profiles in your Apple Developer account.
The password is only used to authenticate with Apple and never stored.
? Apple ID: [hidden]
? Password (for [hidden]): [hidden]
Trying to authenticate with Apple Developer Portal...
Authenticated with Apple Developer Portal successfully!
Only 1 team associated with your account, using Apple Team with ID: [hidden]
We do not have some credentials for you: Apple Distribution Certificate, Apple Push Notifications service key, Apple Provisioning Profile
? How would you like to upload your credentials? Expo handles all credentials, you can still provide overrides
? Will you provide your own Apple Distribution Certificate? Let Expo handle the process
? Would you like to reuse Apple Distribution Certificate from another app? No, please create a new one
? Will you provide your own Apple Push Notifications service key? Let Expo handle the process
? Would you like to reuse Apple Push Notifications service key from another app? No, please create a new one
✔ App ID found on Apple Developer Portal.
We're going to generate:
- Apple Distribution Certificate
- Apple Push Notifications service key
- Apple Provisioning Profile
✔ Generated Apple Distribution Certificate
✔ Generated Apple Push Notifications service key
✔ Generated Apple Provisioning Profile
Encrypted credentials and saved to the Expo servers
Unable to find an existing Expo CLI instance for this directory, starting a new one...
Starting Metro Bundler on port 19001.
Tunnel ready.
Publishing to channel 'default'...
Building iOS bundle
Finished building JavaScript bundle in 1413ms.
Building Android bundle
Finished building JavaScript bundle in 1103ms.
Analyzing assets
Finished building JavaScript bundle in 830ms.
Finished building JavaScript bundle in 757ms.
Uploading assets
No assets changed, skipped.
Processing asset bundle patterns:
- /Users/shomariewing/Public/expo/four-post-expo/**/*
Uploading JavaScript bundles
Published
Your URL is

[hidden]

Checking if this build already exists...

Build started, it may take a few minutes to complete.
You can check the queue length at https://expo.io/turtle-status

You can monitor the build at

 [hidden]

Waiting for build to complete. You can press Ctrl+C to exit.
✔

It’s shown here in your logs that it was generated.

Yes this works for development but in apple developer when looking at certificates I do not see a push notification cert created for production. There are also several other posts here that state that this has to manually be done. See @vglobal response in this post IOS push notification permission status undetermined - #4 by charliecruzan.

Based on all the research i’ve done i’m pretty sure I am going to have to generate a production push cert through apple developer and manually upload it to expo. I am a super noob at this so I was trying to avoid manually doing this and wanted to confirm that is what is needed to happen.

Also very similar issue to these posts so its not just me that is having this.

Also ongoing github issue with pretty much the same problem

1 Like

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