1

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:

  1. I am using a real iPhone, not the simulator
  2. Tried on cellular and WiFi
  3. Created new bundle IDs
  4. Checked that app Identifier is explicit (no wildcard)
  5. Cleared all certificates from Keychain.app and ~/Library/MobileDevice/Provisioning Profiles/
  6. Re-registered device with developer account
  7. Deleted and recreated development certificates from developer.apple.com
  8. Regenerated, downloaded, and re-installed the development certificate multiple times
  9. Tried the above with both manual and “Automatically manage signing” in Xcode
  10. Confirmed provisioning profile contains the aps-environment entry (screenshot)
  11. Added “Background Modes: notifications” to capabilities/entitlements
  12. Tried removing notification and background capabilities then re-adding them
  13. Confirmed that other AppStore apps can send notifications to the device
  14. Checked that APNS server is up
  15. Restarted device multiple times between all the above changes
  16. 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)");
    }

}
N S
  • 2,524
  • 6
  • 32
  • 42

1 Answers1

0

Turns out it was an issue on Apple's end. Here's the message I received from Developer Support:

Follow-up: 736344716

Hi,

The issue we have recognized is that the timeout for the register call is too long to be useful in normal cases. By the time the registration process decides to timeout and send an error, the app is long gone, and the developer/user has given up. This is going to be addressed in a future iOS release. In the meantime, if this happens again, please make sure your device can access *.push.apple.com on TCP ports 80, 443, 2197, and 5223

I am going to request your TSI to be credited back to your account.

N S
  • 2,524
  • 6
  • 32
  • 42