My device suddenly stopped receiving push notifications from my app, despite it working just a few minutes before.
- the device has granted notification permissions, the APNS certificate is still valid, and push notifications are enabled in xcode under Signing and Capabilities
didRegisterForRemoteNotificationsWithDeviceToken
is being run, and my device is sending its token to my server- My server is sending the notification bundle, including my token, to Apple when it should.
Here is my AppDelegate
:
import UserNotifications
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
registerForPushNotifications()
return true
}
func registerForPushNotifications() {
UNUserNotificationCenter.current()
.requestAuthorization(options: [.alert, .sound, .badge]) {
[weak self] granted, error in
print("Permission granted: \(granted)")
guard granted else { return }
self?.getNotificationSettings()
}
}
func getNotificationSettings() {
UNUserNotificationCenter.current().getNotificationSettings { settings in
print("Notification settings: \(settings)")
guard settings.authorizationStatus == .authorized else { return }
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
let token = tokenParts.joined()
print("Device Token: \(token)")
global_device_token = token
}
None of the above has changed from when it was working just a few minutes ago. The only that that has changed is that multiple device tokens were sent to my server, which is now sending all of those tokens to Apple. I have tried deleting the app and reinstalling, disabling wifi, and restarting my device. This is on both an iPhone 8 and 8 Plus, running iOS 13.4