iOS Push Notification Integration
This document provides step-by-step instructions to create an APNs Authentication Key (.p8) from Apple Developer, add the GoogleService-Info.plist file to the project, and configure necessary settings in Firebase Console.
The goal is to enable push notification delivery to iOS devices via Firebase.
📋 Prerequisites
| Requirement | Description | Notes |
|---|---|---|
| ✅ Apple Developer Account | Apple Developer account required | See iOS TestFlight Integration for details. |
| ✅ Firebase Project | Firebase project must be created | See iOS Firebase Integration for details. |
| ✅ iOS App created with Xcode | The app must be registered in Firebase | |
| ✅ Physical iOS device | Required for push testing (simulator not supported) |
🧩 1. Firebase Setup
Follow the document for creating a Firebase project and adding the GoogleService-Info.plist file to the project:
🧩 2. App Store Connect and Apple Developer Setup
Follow the document for Apple Developer account setup and app registration:
🔑 3. Create APNs Authentication Key (.p8)
- Log in to Apple Developer at Apple Developer Auth Keys.
- Click the "+" (Create a key) button at the top right.
- Fill in required information:
- Key Name: e.g.,
FCM APNs Key - Services: Select Apple Push Notifications service (APNs) ✅
- Key Name: e.g.,
- Click Continue > Register, then download the .p8 file.
- Note these values:
- Key ID (shown on the main page)
- Team ID (found under Membership)
☁️ 4. Upload APNs Key to Firebase Console
- Go to Firebase Console > Project Settings > Cloud Messaging tab.
- Scroll down to iOS App Configuration > APNs Authentication Key section.
- Upload the .p8 file.
- Fill in Key ID and Team ID fields.
- Click Save.
✅ Firebase is now authorized to connect to APNs!
⚙️ 5. iOS App Push Notification Setup
Ensure FirebaseMessaging SDK is installed.
- Add the following code in
AppDelegate.swift:
import UIKit
import Firebase
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in
print("Push permission: \(granted)")
}
application.registerForRemoteNotifications()
Messaging.messaging().delegate = self
return true
}
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}
}
MessagingDelegateandUNUserNotificationCenterDelegateExtensions:
extension AppDelegate: MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
// Send token to backend
NotificationServiceV2Helper.shared.saveFCMToken(fcmToken)
}
}
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .badge, .sound])
}
}
🚀 6. Test: Send Push via Firebase Console
- Go to Firebase Console > Cloud Messaging.
- Click Send your first message.
- Enter title and message.
- Select Test on device.
- Enter the FCM token retrieved from the iOS device.
- Click Send Test Message.
✅ Push notification should appear on the device.
🧠 Notes & Tips
- The .p8 APNs key is valid for all your apps (one key for all bundle IDs).
- Push notifications do not work on the simulator; testing must be on a physical device.
- If you don't have a physical device, upload your app to TestFlight and ask someone with a real device to test.
- To receive push notifications:
- Notification permission must be granted.
- Device must have an internet connection.
- FCM token must be sent correctly to your backend.
💬 FAQ
Q: When I visit https://developer.apple.com/account/resources/, I get this error:
Access Unavailable
This resource is only for developers enrolled in a developer program or members of an organization's team in a developer program.
A: You need to be added to the Apple Developer account by an authorized person. See step 2 for details.
Q: When I visit https://developer.apple.com/account/resources/authkeys/list, I get this error:
You are not allowed to perform this operation. Please check with one of your Team Admins, or, if you need further assistance, please contact Apple Developer Program Support.
https://developer.apple.com/support
A: You need to be added to the Apple Developer account by an authorized person. See step 2 for details.