iOS Push Notifications Setup
Complete guide to setting up Apple Push Notifications (APNs) for your iOS app with Retenshun.
Prerequisites
- Apple Developer account ($99/year) — developer.apple.com
- Xcode installed on a Mac
- A physical iOS device (push notifications don't work on simulator)
- Retenshun SDK integrated in your app
Enable Push in Xcode
Open your project in Xcode
For Flutter: Open ios/Runner.xcworkspace (not .xcodeproj)
For React Native: Open ios/YourApp.xcworkspace
For native Swift/ObjC: Open your .xcodeproj or .xcworkspace
Add Push Notifications capability
- Select your app target (e.g. Runner) in the left sidebar
- Click the Signing & Capabilities tab
- Click + Capability in the top left
- Search for and add Push Notifications
This adds the aps-environment entitlement to your app.
Add Background Modes capability
- Click + Capability again
- Search for and add Background Modes
- Check Remote notifications
This allows your app to receive push notifications in the background and perform silent updates.
Generate an APNs Authentication Key (.p8)
Important: Save your .p8 file!
Apple only lets you download the .p8 key file once. If you lose it, you must create a new key. Store it securely.
Steps in Apple Developer Portal
- Go to Certificates, Identifiers & Profiles → Keys
Direct link: developer.apple.com/account/resources/authkeys/list
- Click the + button to create a new key
- Enter a name (e.g. "Retenshun Push Key")
- Check Apple Push Notifications service (APNs)
- Click Continue → Register
- Download the .p8 file immediately! Save it somewhere safe.
- Note the Key ID shown on the confirmation page (10 characters, e.g.
ABC123DEF4)
Find your Team ID
- Go to Account → Membership Details
- Your Team ID is a 10-character alphanumeric string (e.g.
9ABCDE1234)
You now have 3 values
| Value | Example | Where to find |
|---|---|---|
| .p8 file | AuthKey_ABC123DEF4.p8 | Downloaded after key creation |
| Key ID | ABC123DEF4 | Key confirmation page |
| Team ID | 9ABCDE1234 | Membership Details page |
Add APNs Key to Push Provider
Option A: Using default Retenshun push (recommended)
Contact the Retenshun team to upload your APNs key to the shared push infrastructure. Provide:
- Your
.p8file - Key ID
- Team ID
- Bundle ID (e.g.
com.yourcompany.yourapp)
Option B: Using your own OneSignal app
- Go to OneSignal Dashboard → your app → Settings → Platforms
- Click Apple iOS (APNs)
- Select .p8 Auth Key (Token Based) — Recommended
- Upload your
.p8file - Enter your Key ID
- Enter your Team ID
- Enter your Bundle ID (must match your Xcode target)
- Click Save
The .p8 key is recommended over .p12 certificates because it never expires and works for all your apps under the same Apple Developer account.
Test on a Real Device
Build and run on your iPhone/iPad
- Connect your device via USB or use wireless debugging
- Select your device as the build target in Xcode / VS Code
- Run the app — it should prompt for notification permission
- Tap Allow
- Check your Retenshun dashboard — the device should appear under registered devices
Send a test push
curl -X POST https://your-retenshun-domain.com/api/v1/messages \
-H "Authorization: Bearer sk_live_YOUR_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{
"user_id": "your_user_id",
"channel": "push",
"content": {
"title": "iOS Push Test",
"body": "If you see this, iOS push is working!"
}
}'Troubleshooting
No permission prompt appears
- Make sure you're running on a real device (not simulator)
- Check that Push Notifications capability is added in Xcode
- Check Settings → your app → Notifications to see if permission was already denied
- Try deleting the app and reinstalling
Permission granted but no notifications received
- Verify your APNs key is uploaded correctly (Key ID, Team ID, Bundle ID must all match)
- Check if using sandbox vs production — debug builds use sandbox APNs, release builds use production
- Wait 1-2 minutes — iOS push delivery can be delayed
- Check OneSignal delivery report for errors
Notifications arrive but without sound
- Check device is not in Focus/Do Not Disturb mode
- Check Settings → your app → Notifications → Sounds is enabled
"InvalidProviderToken" or "BadDeviceToken" errors
- InvalidProviderToken: Key ID or Team ID is wrong, or .p8 file is from a different account
- BadDeviceToken: The token was generated in sandbox but sent to production, or vice versa
- Make sure the Bundle ID in OneSignal matches your Xcode target exactly
.p8 Key vs .p12 Certificate
| .p8 Key (Recommended) | .p12 Certificate | |
|---|---|---|
| Expires | Never | Every year |
| Works for | All apps in your account | One app only |
| Environment | Sandbox + Production | Separate certs needed |
| Setup | 3 clicks in Apple portal | Complex Keychain process |