I have absolutely no clue why my notifications are not working.
My AppDelegate looks like this:
Code Block import UIKit import UserNotifications @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate { /// The base UIWindow var window: UIWindow? func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined() print("token: \(token)") } func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { print("Failed to register for remote notifications with error: \(error))") } func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. UNUserNotificationCenter.current().delegate = self UIApplication.shared.registerForRemoteNotifications() UNUserNotificationCenter.current().requestAuthorization( options: [.alert, .badge, .sound], completionHandler: { (granted, error) in print("access granted!") guard granted else { return } DispatchQueue.main.async { UIApplication.shared.registerForRemoteNotifications() print("Registered: \(UIApplication.shared.isRegisteredForRemoteNotifications)") } }) return true } // MARK: UISceneSession Lifecycle func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { // Called when the user discards a scene session. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. // Use this method to release any resources that were specific to the discarded scenes, as they will not return. } }
The problem is, function "didRegisterForRemoteNotificationsWithDeviceToken" is never getting called.
I also created "Apple Push Notification service SSL Certificates" in my developer account, added "Push Notifications" to my capabilities in Xcode but it's still not working. Every time I tab on "Allow" to allow notifications, it says "access granted", but it does not print out any device token. "isRegisterForRemoteNotifications" also returns true.
I also searched on the internet for around 2-3 hours, but I couldn't find any solution yet.
I'm using Xcode 12 Beta 2 and iOS 14 Dev Beta 2.
Thank you.