Key Takeaways
- APNs Keys and Certificates authenticate app servers for sending push notifications.
- Keys are modern, never expire, and work across multiple apps, while certificates require yearly renewal.
- Proper credential management is crucial for app security and functionality.
- Developers must follow Apple's guidelines when implementing APNs.
APNs keys play a vital role in enabling push notifications for iOS apps. They allow developers to securely send messages to Apple devices through the Apple Push Notification service (APNs). An APNs key is a cryptographic token that authenticates your app server with Apple's servers, ensuring only authorized notifications reach users' devices.
Setting up APNs keys can seem complex at first, but it's an essential step for iOS developers who want to engage users with timely updates. This article will guide you through the process and help you understand the importance of APNs keys in mobile app development.
What Is an APNs Key?

An APNS Key is a unique identifier that allows an app's server to connect with Apple's push notification service. It acts as a digital signature, proving that the server has permission to send notifications to the app's users. Without a valid APNS Key, an app cannot receive push notifications, which are crucial for user engagement and app functionality.
There are two types of APNs keys:
- Development keys
- Production keys
Development keys are used for testing, while production keys are for live apps.
APNs Keys vs. Certificates: Which Should You Use?
Apple offers two authentication methods for APNs: keys (token-based) and certificates. Understanding the differences helps you choose the right approach for your app.
APNs Keys (Token-Based Authentication):
- Never expire - No yearly renewal required
- Work across multiple apps - One key for your entire team
- Easier to manage - No complex certificate management
- More secure - Uses JSON Web Tokens (JWT)
- Recommended by Apple for new implementations
APNs Certificates:
- Expire annually - Must be renewed every year
- App-specific - Separate certificate for each app
- Legacy method - Older authentication approach
- Still widely used - Many existing apps rely on certificates
For new projects, Apple recommends using APNs keys. However, certificates are still fully supported and widely used. This guide covers both methods to help you implement or maintain either approach.
Overview of Apple Push Notification Service
APNs stands for Apple Push Notification service. It's a system that lets app developers send notifications to iOS devices. It allows developers to send messages to users even when their apps aren't running. These notifications can include alerts, sounds, and badge updates.
APNs works by maintaining a constant connection between Apple's servers and iOS devices. When a notification is sent, it goes through Apple's servers and then to the user's device.
Push notifications can be used for various purposes:
- News updates
- Message alerts
- Game invites
- Reminders
They help keep users engaged with apps and provide timely information.
How To Generate an APNs Key

APNs keys are essential for secure communication between your app and Apple's push notification servers. They provide a modern, more flexible alternative to traditional certificates. Proper configuration and management of APNS keys are crucial for implementing push notifications in iOS apps.
Step 1: Access Your Apple Developer Account
To create an APNS Key, developers must log into their Apple Developer account. This account is the central hub for managing all aspects of iOS app development.
Step 2: Navigate to Certificates, Identifiers & Profiles
In the developer portal, find the section for Certificates, Identifiers & Profiles. This area contains all the necessary tools for creating and managing app-related credentials.
Step 3: Create a New Key
Click on "Keys" in the sidebar and select the "+" button to add a new key. Choose "Apple Push Notifications service (APNs)" from the list of key services.
Step 4: Configure Key Settings
Name the key and select the app ID it will be associated with. This step ensures the key is linked to the correct application.
Step 5: Generate and Download
After confirming the settings, generate the key. After creating the key, you'll see its Key ID, and Apple will create a unique .p8 file. Download this file immediately, as it can only be downloaded once for security reasons.
Step 6: Secure Your APNS Key File
Store the APNS key file in a secure location with limited access. Use encryption tools to protect the file when it's not in use. Implement strict access controls, allowing only authorized admins to handle the key.
Consider using a hardware security module (HSM) for added protection. HSMs provide a secure environment for storing sensitive cryptographic keys.
Integrating APNs Keys with Your Application

Screenshot from Apple Developer
Integrating APNs keys into your app involves a few steps. First, add the key to your Xcode project by going to project settings and selecting your target.
Under the "Signing & Capabilities" tab, add the "Push Notifications" capability. This updates your app’s entitlements to support push notifications.
Next, generate a JSON Web Token (JWT) using your APNs key. This token authenticates your app with Apple's servers.
Include the following in your JWT:
- Key ID
- Team ID (from your developer account)
- Bundle ID of your app
Use libraries like jwt-simple to create the token. Sign it with your private key from the downloaded key file.
Sending Push Notifications via APNs
Once your app is configured with APNs authentication, you can send push notifications by following these steps:
- Create a push notification payload – A JSON object containing the message content and any custom data.
- Connect to Apple's servers using HTTP/2 – Authenticate using your APNs key and JWT.
- Send the payload – Include the device token of the intended recipient so Apple can route the notification.
Keep these best practices in mind when sending push notifications via APNs:
- Use topic-based notifications for improved targeting.
- Implement error handling to manage failed deliveries.
- Respect user preferences and local regulations to avoid spam complaints.
Best Practices for Key Storage and Usage
To manage existing keys, return to the Keys section in your developer account. Here you can view key details, edit names, or revoke keys if needed. Follow these best practices to store your APNs keys securely:
- Regularly audit access logs to monitor who has interacted with the key file. This helps detect any unauthorized access attempts quickly.
- Implement robust security measures for your APNs key. Use strong, unique passwords for any systems storing the key. Enable two-factor authentication for added security.
- Rotate your APNs keys periodically to reduce the risk of compromise. Apple recommends changing keys at least once a year.
- Never share your APNs key through unsecured channels like email. Use secure file transfer protocols when moving the key between systems.
- Keep your server software up-to-date to patch any security vulnerabilities. Regularly review and update your key management policies to adapt to new threats.
Understanding APNs Certificates
For developers using certificate-based authentication, it's important to understand how APNs certificates work and why they're necessary.
What Is an APNs Certificate?
An APNs certificate is a digital credential that authenticates your app's server with Apple's push notification service. Think of it as a secure handshake between your server and Apple, proving your app is legitimate and authorized to send notifications.
There are two types of APNs certificates:
- Development certificates - Used during testing and debugging
- Production certificates - Used for live apps sending notifications to real users
Why You Need an APNs Certificate
APNs certificates are essential for several reasons:
- Enabling push notifications: Certificates are mandatory for apps using certificate-based authentication. Without them, you can't use Apple's push notification system.
- Securing communications: An APNs certificate authenticates your app's server, telling Apple you're a trusted source. This protects users from unauthorized messages and spam.
- App Store compliance: All iOS and macOS apps must have proper APNs authentication to message Apple users. Failing to get proper authentication will result in falling out of compliance with Apple.
How APNs Certificates Work
APNs certificates participate in a three-stage authentication process:
-
Device token generation: When a user installs your app and agrees to receive notifications, the app contacts APNs to request a unique device token. This token is like a personalized address for the user's device, ensuring notifications go to the right place.
-
Certificate authentication: Before your app server can send notifications, APNs needs to verify your identity. The app server includes the APNs certificate in its requests to APNs. APNs verifies that certificate, which authorizes your server to send notifications via the gateway.
-
Secure data transmission: The app server prepares the notification message in JSON format, encrypts it, and sends it to the APNs gateway. APNs decrypts the message and matches it to the user's device using the token.
How to Create an APNs Certificate

Screenshot from Apple Developer Program
If you're setting up certificate-based authentication for the first time, follow these steps to create an APNs certificate:
Step 1: Sign Up for the Apple Developer Program
Create an active account with the Apple Developer Program, which gives you access to all resources needed to create APNs certificates. Note that membership starts at $99 a year.
Step 2: Create a Certificate Signing Request (CSR)
Apple needs information about your systems before generating a certificate. Open Keychain Access on macOS and go to Certificate Assistant > Request a Certificate from a Certificate Authority.
Enter the email address associated with your Apple Developer account, name the request, and select "Saved to disk" under Request. Save the CSR file to your computer.
Step 3: Create the Certificate
With CSR in hand, return to your Apple Developer Portal and go to Certificates > Identifiers & Profiles. Click the + button to create a new certificate.
Choose whether you want a development or production APNs certificate, then upload your CSR file.
Step 4: Download and Install the Certificate
The Apple Developer Portal will generate a certificate file. Download it and double-click to install it in Keychain Access.
Next, open Keychain Access to export this certificate in .p12 format for your server. Locate the APNs certificate under My Certificates and export it. Set a strong, secure password for the file before exporting.
Finally, integrate the .p12 certificate into your app's backend. This allows your server to authenticate with APNs and start sending push notifications.
Step 5: Test Your Certificate
Before deploying to production, test your push notifications to ensure everything works. Use tools like Postman or built-in testing features in services like Firebase to confirm proper setup. For web push notifications, visit webpushtest.com for a demo across all platforms.
How to Renew an APNs Certificate

Photo by Faded_Gallery from Unsplash
APNs certificates expire annually and must be renewed to maintain push notification functionality. Failing to renew will prevent your app from sending notifications to users. Follow these steps to renew your certificate:
Step 1: Check Your Certificate's Date and Back It Up
Log into your Apple Developer account and check the expiration date of your current APNs certificate. You can view this in the Certificates section.
Download a copy of your current certificate as a backup in case you need to revert changes. Make sure you're using the developer account associated with the APNs certificate.
Step 2: Go to the Apple Push Certificates Portal
Identify your Apple ID and bundle ID for the app associated with the certificate. Then go to the Apple Push Certificates Portal in your Apple Developer account.
Find the expiring certificate and verify it matches your app's settings. Click Renew next to the expiring certificate.
Apple may ask you to upload a Certificate Signing Request (CSR). You can get this from your server, mobile device management (MDM) solution, or Keychain Access in macOS.
Step 3: Download and Install the New Certificate
Download the renewed APNs certificate and save it in a secure location. Access your server's certificate management tool and import the renewed certificate.
Finally, send a test notification to confirm the new certificate works properly. If you're setting up web push notifications, use webpushtest.com for standards-based testing across all platforms.
Certificate Best Practices
If you're using certificate-based authentication, follow these best practices:
Regularly Renew Your Certificate
APNs certificates expire after one year. Set calendar reminders to renew at least a month before expiration. Apple will send reminder emails, but don't rely solely on these—create your own tracking system.
Consolidate APNs Certificates
Apple allows a single APNs certificate per app. If you have multiple certificates for the same app, consolidate them to minimize confusion and management overhead.
Prioritize Security
Protect your APNs credentials with these security measures:
- Protect your .p12 file: Always create a strong, unique password when exporting the file. Store it in a secure location with limited access.
- Enable MFA or 2FA: Protect your Apple Developer account with multi-factor or two-factor authentication.
- Rotate certificates regularly: Some developers rotate certificates more frequently than once a year for added security.
- Use encryption: Implement encryption tools to protect certificate files when not in use.
- Strict access controls: Allow only authorized administrators to handle certificates.
Optimize Payload Size
Apple limits push notification payloads to 4KB. Keep messages concise and compress data where possible. Use deep links or in-app content to share detailed information rather than including everything in the notification.
Consider Migrating to Token-Based Authentication
Token-based authentication (APNs keys) offers significant advantages over certificates:
- Never expires
- Works across multiple apps
- Easier to manage
- More secure
For new projects or major updates, consider migrating to token-based authentication for improved security and reduced maintenance.
Troubleshooting Common APNS Issues
Connection problems are a frequent issue. Check your internet connection and firewall settings. Then, verify that your APNS key is valid and not expired.
Invalid device tokens can cause delivery failures. Regularly update your database to remove outdated tokens.
If notifications aren't received, ensure the app has permission to display them. Then, check the user's notification settings on their device.
Payload issues may prevent delivery. Verify your JSON format is correct and within size limits.
Lastly, monitor Apple's APNS status page for any system-wide problems affecting notification delivery. Also, use Apple's feedback service to identify and remove invalid device tokens, improving overall delivery rates.
Simplify Push Notifications with MagicBell
MagicBell is a masterclass in SaaS success 🎯
In 2024, MagicBell proved the power of solving real problems. Their plug-and-play notification system saves dev teams time & resources while scaling with businesses.
💡 Key wins:
- $1M ARR with just 100 clients (ARPU: $10K)
-… pic.twitter.com/w9YIlZVBSz— Niko Steller 🤓 (@nikosteller) December 27, 2024
APNs keys play a vital role in enabling push notifications for iOS apps. They provide secure authentication between app servers and Apple's push notification service.
APNs keys unlock powerful capabilities for engaging users through timely notifications. They allow apps to send targeted messages and updates.
Developers looking to implement push notifications can benefit from push notification services. These simplify the process of managing keys and sending notifications at scale.
MagicBell handles the complexities of notification delivery across platforms, allowing you to deliver seamless, real-time notifications across channels. Start your free MagicBell trial now to get started.
Frequently Asked Questions
What is the difference between APNs certificates and APNs keys?
APNs certificates are older and require yearly renewal. On the other hand, APNs keys are newer, don't expire, and can be used across multiple apps. Keys are easier to manage and more secure than certificates. Apple recommends token-based authentication (keys) for new implementations.
What happens if my APNs certificate expires before I renew it?
Apple will suspend your ability to send push notifications if your APNs certificate expires. Users can't receive notifications until you renew the certificate and integrate it with your server. It's best to renew long before the certificate expires to avoid disruptions.
Do I need a separate APNs certificate for development and production?
Yes. Apple requires separate APNs certificates for development and production environments. Development certificates are used during app testing, while production certificates are for the live app.
Can I renew an APNs certificate using a different Apple ID?
No. You must use the same Apple ID that created the original certificate. Using a different Apple ID will create a new certificate that isn't compatible with your existing app setup, which could disrupt notifications.
What are the steps to retrieve an APNs authentication key?
APNs keys can only be downloaded once when created. If you lose the key, you'll need to create a new one. Always store the key securely after downloading it from the Apple Developer portal.
How can I find my existing APNs key in the Apple Developer portal?
Log into the Apple Developer portal and go to Certificates, Identifiers & Profiles. Then, click on Keys in the sidebar. You'll see a list of your existing keys, including any APNs keys you've created.
Is there a limit to the number of APNs keys I can generate?
Apple allows developers to create up to two active APNs keys per account. If you need a new key and have reached the limit, you'll need to revoke an existing key first.
How do I obtain an APN token for sending notifications?
To get an APN token, use your APNs key to sign a JSON Web Token (JWT). This JWT serves as your authentication token when connecting to Apple's push notification service. The token is valid for one hour.
What is the difference between APNs and Firebase Cloud Messaging?
Apple Push Notification Service (APNs) is Apple's push notification service. It requires either an APNs certificate or token to connect your app and Apple servers. Firebase Cloud Messaging (FCM) is Google's push notification service, but it supports iOS, Android, and web applications.
