How to Fix iOS Push Notification Not Received
In this tutorial, you'll learn about How to Fix iOS Push Notification Not Received. We cover key concepts, practical examples, and best practices.
The Problem
Your app registers for remote notifications but they never arrive:
Failed to register: Error Domain=NSCocoaErrorDomain Code=3010
"Remote notifications are not supported in the simulator"
Or notifications work in development but not in production.
Quick Fix
Step 1: Enable push notifications capability
In Xcode: Target > Signing & Capabilities > + > Push Notifications.
Also enable Background Modes > Remote notifications.
Step 2: Register for remote notifications in code
import UserNotifications
// Request authorization
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
guard granted else { return }
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
Step 3: Implement the delegate methods
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let tokenString = deviceToken.map { String(format: "%02x", $0) }.joined()
// Send tokenString to your server
}
func application(_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Failed to register: \(error)")
}
Step 4: Use a physical device for testing
The simulator does not support remote push notifications. Test on a real device with a valid Apple Developer account.
Step 5: Verify APNs certificate
For production push, generate a Universal APNs Certificate (not a Development certificate) on developer.apple.com.
In your server, use the correct APNs endpoint:
| Environment | Host |
|---|---|
| Development | api.sandbox.push.apple.com |
| Production | api.push.apple.com |
Step 6: Test with a push tool
# Using knuff or Pusher GUI tool
# Payload example:
{
"aps": {
"alert": "Hello!",
"sound": "default",
"badge": 1
}
}
Use a push testing tool to send a test notification directly to the device token before relying on your server.
Step 7: Check bundle identifier match
The APNs certificate must match the app's bundle ID exactly. A mismatch causes silent delivery failure.
Step 8: Handle notification content extensions
For rich notifications (images, video), add a Notification Service Extension target:
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
// Download and attach media
}
Prevention
- Register for remote notifications only after obtaining user permission.
- Send the device token to your server every time
didRegisterForRemoteNotificationsWithDeviceTokenis called. - Test push notifications before every release.
Common Mistakes with push notification
- Using
foldlinstead offoldl'causing stack overflow on large lists - Forgetting
deriving (Show, Eq)on custom data types needed for debugging - Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
These mistakes appear frequently in real-world IOS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
DodaTech Tool Reference
Doda Browser's Notification Tester can simulate push notification delivery to connected devices, helping debug payload formatting and display issues.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro