This can be reproduced from scratch in just 2 minutes:
create a brand new iOS app and give it the push notification capability.
Change the app delegate template code to this:
@main
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UNUserNotificationCenter.current().delegate = self
// UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in
// NSLog("Notification permission granted: \(granted)")
// DispatchQueue.main.async {
application.registerForRemoteNotifications()
// }
// }
NSLog("didFinishLaunchingWithOptions returning")
return true
}
// Called when an APNS token has been sucessfully obtained
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
NSLog("Apn Push token: \(token)")
}
// Called when APN token request fails
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
NSLog("❗️Failed to register for remote notifications: \(error)")
}
Neither didRegisterForRemoteNotificationsWithDeviceToken() nor didFailToRegisterForRemoteNotificationsWithError() get called.
Now uncomment the code and didRegisterForRemoteNotificationsWithDeviceToken() will get called.
So based on this experiment, requestAuthorization() is a requirment.
Now where does it state that in the Apple documentation, it doesn't, how does this code differ from what's in the Apple documentation, it doesn't.
https://developer-mdn.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/HandlingRemoteNotifications.html#//apple_ref/doc/uid/TP40008194-CH6-SW4