I'm experiencing issues with didRegisterForRemoteNotificationsWithDeviceToken not being called on iOS 18.1.1. Here's what I've tried:
Basic Setup:
- Properly configured UNUserNotificationCenter
- Requested permissions with requestAuthorization(options:)
- Registered for remote notifications with registerForRemoteNotifications()
Environment:
- Xcode 16.3
- iOS 18.1.1 (physical device)
- Firebase (tried with and without it)
Troubleshooting:
- Verified provisioning profile includes Push Notifications
- Confirmed APNs certificate is valid
- Disabled Firebase's method swizzling
- Tested on a clean project (works fine)
- Checked device logs (no relevant errors)
Code Snippet:
// In AppDelegate.swift
public func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
let tokenString = tokenParts.joined()
print("📱 Device Token: \(tokenString)")
// Store the token for your backend
UserDefaults.standard.set(tokenString, forKey: "deviceToken")
// Send to backend
Task {
do {
try await APIService.shared.setDeviceToken(tokenString)
} catch {
print("❌ [AppDelegate] Failed to send device token to backend: \(error)")
}
}
}
public func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
// IMPORTANT: First handle push notification registration
UNUserNotificationCenter.current().delegate = self
// Request notification permissions
self.requestNotificationPermissions()
// Register for remote notifications
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
return true
}
private func requestNotificationPermissions() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in
guard granted else {
print("❌ Notification permission not granted")
return
}
print("✅ Notification permission granted")
}
}