# Give Firebase your Apple push key (APNs key)

The step `firebase_messaging.apns_key`, for [`firebase_messaging`](https://doc.saymyframe.com/modules/firebase-messaging.md).

Firebase sends push messages to iPhones through the Apple Push Notification service (APNs). For that it needs a key from your Apple Developer account. Without the key the app still gets its address for push messages, but Firebase cannot send anything to it.

You need a paid Apple Developer account and access to your Firebase project. You make the key once for your team, and it works for all of its apps.

:::tip
The screenshots use example values: the Team ID `SAYMYFRAME`, the Key ID `SMFAPNSKEY`, the bundle id `com.example.my-app` and the Firebase project `my-app-12345`. You will see your own. The orange frames mark what to click, in the order of their numbers.
:::

**1. Find your Team ID.** Open [your Apple Developer account](https://developer.apple.com/account) and scroll to **Membership details**. Copy the **Team ID**: ten letters and digits.

![Membership details of an Apple Developer account, with the Team ID SAYMYFRAME framed](https://doc.saymyframe.com/assets/images/team-id-17919a1429cf0d0b47090ee600c2a346.png)

**2. Create the key.** In the account, under **Certificates, IDs & Profiles**, click **Keys** (1).

![Program resources of the account, with Keys under Certificates, IDs and Profiles marked 1](https://doc.saymyframe.com/assets/images/account-keys-c0a1eec126c2c7b43e7a12ae1902377c.png)

Click the **+** next to the title (2).

![The Keys page, with the plus button next to the title marked 2](https://doc.saymyframe.com/assets/images/keys-list-9930773b1597b33ef01ba6acb6ed0278.png)

Give the key a name (1), such as `My App APNs`, and check **Apple Push Notifications service (APNs)** (2). Then click **Configure** (3) in the same row.

![Register a New Key, with the name My App APNs marked 1, the checked APNs service marked 2 and its Configure button marked 3](https://doc.saymyframe.com/assets/images/new-key-apns-ac4a4bc20a81c5a26dacd9dacdc6f2aa.png)

Set **Environment** to **Sandbox & Production** (1) and **Key Restriction** to **Team Scoped (All Topics)** (2), then click **Save** (3). One key then serves debug builds and App Store builds alike. Apple does not let you change these two settings later.

![Configure Key, with the environment Sandbox and Production marked 1, the restriction Team Scoped marked 2 and Save marked 3](https://doc.saymyframe.com/assets/images/configure-apns-10afc1d4d5be1133cad1b20f3ff7ac76.png)

Click **Continue**, then **Register**.

**3. Download the key.** On the page of the key, click **Download** (1). You get a file named `AuthKey_<Key ID>.p8`. Copy the **Key ID** (2) from the same page.

![View Key Details, with the Download button marked 1 and the Key ID SMFAPNSKEY marked 2](https://doc.saymyframe.com/assets/images/apns-key-details-b7bcde33fcb75d6f15522044a83a7aa1.png)

:::warning
Apple lets you download the file **only once**. Keep it in a password manager. The file is a secret: never put it into the app or its repository. If you lose it, revoke the key and create a new one.
:::

**4. Open Cloud Messaging in Firebase.** In the [Firebase console](https://console.firebase.google.com/), open your project. In the menu on the left, point at **Settings** (1) and click **General** (2). On the page **Project settings**, open the tab **Cloud Messaging**.

![The menu of the Firebase console, with Settings and its item General marked 1 and 2](https://doc.saymyframe.com/assets/images/project-settings-menu-d9498eaae0d38e2fb59029b536200ab1.png)

Scroll to **Apple app configuration** and select your iOS app on the left. Under **APNs Authentication Key**, click **Upload** (1) in the row **No development APNs auth key**.

![Apple app configuration, with the app my_app and the Upload button of the development key marked 1](https://doc.saymyframe.com/assets/images/apns-upload-button-b946d5a1074b636e982f452f41d19910.png)

**5. Upload the key.** Click **Browse** (1) and choose the `.p8` file, or drag the file onto the dashed area. Enter the **Key ID** (2) and your **Team ID** (3), and click **Upload** (4).

![The dialog Upload development APNs auth key, with Browse, the Key ID SMFAPNSKEY, the Team ID SAYMYFRAME and Upload marked 1 to 4](https://doc.saymyframe.com/assets/images/apns-upload-dialog-9d029363421a5831d8fe91547ce28e95.png)

Do the same in the row **No production APNs auth key**, with the same file and the same ids.

**Check.** Both rows now show the key with its Key ID and Team ID.

![The APNs Authentication Key table, with the development and the production key of the Key ID SMFAPNSKEY](https://doc.saymyframe.com/assets/images/apns-key-uploaded-9556f101a8aeb8d4cf7738788abbae3e.png)

To see that it works, run the app on an iPhone, copy the address that it prints in debug mode, and send it a test message from **Messaging** in the Firebase console. [A test message](https://doc.saymyframe.com/guides/firebase.md#a-test-message) tells how.

The key reaches only the apps of its team. So the iOS app also needs an App ID of the same team with **Push Notifications**, which signing the app in Xcode gives it; see [the step about the App ID](https://doc.saymyframe.com/setup/app-entry-ios-app-id.md).
