Get a push notification key for your server
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
- The
aschelp says one APNs key sends pushes to every app on your Apple team, in both sandbox and production. You don’t need a key per app. - Apple limits how many APNs keys a team can hold: see Apple’s Establishing a token-based connection to APNs ↗.
- Apple’s Create a private key to access a service ↗ page says a key’s
.p8file can be downloaded only once.
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.- The Agent makes the key with
asc web push-keys createand 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. - It saves the
.p8file 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. - 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
.gitignoreleaves out, such assecrets/, 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-keyshas 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.