Build, run & install

Have an Agent check your Apple team's APNs keys, make one if you need it, and hand your push server the Key ID, Team ID and key file.

Push notifications reach the people who use your app from a server: your own, or a push service you sign up for. To send them through Apple, that server needs an APNs key from your Apple team. The asc help says a push provider needs three values: the Key ID, the Team ID and the key’s .p8 file. An Agent can make the key and get you all three.

Before you start

  • The Team’s owner has connected an Apple Developer account and switched a team on. See Connect your Apple Developer account.
  • Your app has push notifications turned on. That’s a capability, and making a key doesn’t turn it on. Ask the Agents to add push notifications to the app: see Turn on iCloud, App Groups or another capability.
  • You know which server or push service will send the notifications. That’s where the key goes.

What one key covers

So check what your team has before you make a key.

Check for a key you have

Ask in the Project’s chat:

Which APNs push keys does my Apple team have?

The Agent lists them with asc web push-keys list: each key’s Key ID, its name, and Can Download, whether its file can still be downloaded. Listing downloads nothing and changes nothing.

The list shows What to do
No keys Make a key.
A key whose file you or your server already have Use that key. Give the server the same three values.
A key that can still be downloaded Nobody has its file yet. Download its file.
A key that can’t be downloaded, and nobody has its file The file is gone. Make a new key. If your team has two already, revoke one first in your Apple Developer account: see Apple’s Revoke, edit, and download keys ↗.

Make a key

Ask, for example:

Make an APNs push notification key called "Notes Push" and tell me its Key ID and our Team ID.
  1. The Agent makes the key with asc web push-keys create and the name you gave. The command makes the key and uses up its one download at the same time. It runs only with --confirm, so the Agent asks you first.
  2. It saves the .p8 file in a folder on the computer it works on. The help says the file is never saved over another file, and its contents are never printed.
  3. It tells you the Key ID and where it saved the file.

The Team ID is your Apple team’s ID. Settings › Developer shows it beside each team; see Developer. The Agent can also read it with asc auth list.

If your Apple Account belongs to more than one team, say which one the key is for. The Agent may ask with a card: see Connect your Apple Developer account.

Download a key’s file

For a key that can still be downloaded, ask:

Download the file for the APNs key called "Notes Push".

The Agent saves it with asc web push-keys download and the key’s ID. Apple hands out the file only once, so the command runs only with --confirm, and the Agent asks you first.

Keep the file safe

The three values together let a server send notifications to every app on your Apple team. Treat the file like a password.

  • The help says to keep the file out of the repository and out of logs. Ask the Agent to save it in a folder the project’s .gitignore leaves out, such as secrets/, and to tell you its path. That keeps it out of the repository, a shared link and an export of the source: see Share or export a project’s source. It still shows in Files, dimmed, where anyone in the Team can open it.
  • To take a copy for your server or push service, open it in Files and use Export (see Find the files and documents Agents made), or ask the Agent to send it to you in your DM with that Agent (see Create group chats and talk to one Agent), then touch and hold the file (on the Mac, right-click it) and choose Save As… (see Send photos, files and sketches to an Agent). Don’t ask for the file in the Project’s chat: everyone in the chat can open it, and you can’t recall a message the Agent sent.
  • If the file is lost, it can’t be downloaded again. Revoke the key in your Apple Developer account and make a new one. Agents can’t revoke it: asc web push-keys has no command for that.

Give it to your server

Your server or push service asks for the Key ID, the Team ID and the .p8 file. Where you enter them depends on the service. For how a server of your own uses them to talk to Apple, see Apple’s Establishing a token-based connection to APNs ↗.

A key the Agent makes works in both sandbox and production, so you don’t need another one for testing.

Questions

Can I make a key in AirBuild without an Agent?
No. AirBuild has no screen for APNs keys. Ask an Agent, or make one in your Apple Developer account on the web: see Apple’s Create a private key to access a service ↗.
The Agent says Apple refused the key because the team holds at most two.
No key was made. The message goes on: “one existing key works for every app of the team, so reuse it if your user has its .p8, or ask them which key to revoke”. Use one of your two keys, or revoke one in your Apple Developer account and ask again.
The Agent says a key already has this name.
The message is “already has this name; inspect it instead of creating a duplicate”. Use that key, or give the new one another name.
The Agent says the key exists, but the download failed.
The key was made, but its file didn’t arrive. Don’t ask for a new key straight away: the help says a create is never retried on its own, and to check the list first. Ask the Agent to list the keys. If the key can still be downloaded, ask it to download the file; if not, revoke the key and make another.
It says “Apple denied the request (403)” or that Apple refused the web session.
The 403 message adds: “the account role likely lacks permission for this action, or the web session expired”. If the Team owner’s Apple sign-in has expired, the owner signs in again in Settings › Developer › Sign In Again: see Connect your Apple Developer account. Then ask the Agent to try again.
Can a Worker on AirHost send the notifications?
AirHost has no push notification feature of its own, and the workers help doesn’t say whether a Worker’s code can reach Apple’s push service. Ask the Agent in the chat before you plan on it.