didRegisterForRemoteNotificationsWithDeviceToken has suddenly stopped being called after working for several weeks.
I can reproduce the issue in a fresh Xcode project (.zip) so I’m almost certain it’s a signing/provisioning profile issue. The token is returned as expected in the AppStore version, but not when running from Xcode 11.3 on an iPhone with iOS 13.
I have read through every related question (and followed these steps) but nothing has fixed the issue.
Here’s what I’ve tried:
- I am using a real iPhone, not the simulator
- Tried on cellular and WiFi
- Created new bundle IDs
- Checked that app Identifier is explicit (no wildcard)
- Cleared all certificates from Keychain.app and ~/Library/MobileDevice/Provisioning Profiles/
- Re-registered device with developer account
- Deleted and recreated development certificates from developer.apple.com
- Regenerated, downloaded, and re-installed the development certificate multiple times
- Tried the above with both manual and “Automatically manage signing” in Xcode
- Confirmed provisioning profile contains the aps-environment entry (screenshot)
- Added “Background Modes: notifications” to capabilities/entitlements
- Tried removing notification and background capabilities then re-adding them
- Confirmed that other AppStore apps can send notifications to the device
- Checked that APNS server is up
- Restarted device multiple times between all the above changes
- Tried praying to the push notification gods every day
Any idea what could be going wrong?
The code is extremely straightforward:
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Also tried calling after launch finishes.
// Calling UNUserNotificationCenter.current().requestAuthorization first also never returns a token.
UIApplication.shared.registerForRemoteNotifications();
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// This method is never called.
let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined();
print(" Received notification token: (\(token))");
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
// This method is never called either (unless I remove aps entitlements).
print(" Did fail to register for notifications: \(error)");
}
}