didRegisterForRemoteNotificationsWithDeviceToken and didFailToRegisterForRemoteNotificationsWithError is not getting called on real device.
This what i have tried so far:
In didFinishLaunchingWithOptions
FirebaseApp.configure()
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.badge, .alert, .sound]) {
(granted, error) in
if granted {
DispatchQueue.main.async {
application.registerForRemoteNotifications()
//UIApplication.shared.registerForRemoteNotifications()
}
} else {
//print("APNS Registration failed")
//print("Error: \(String(describing: error?.localizedDescription))")
}
}
} else {
let type: UIUserNotificationType = [UIUserNotificationType.badge, UIUserNotificationType.alert, UIUserNotificationType.sound]
let setting = UIUserNotificationSettings(types: type, categories: nil)
application.registerUserNotificationSettings(setting)
application.registerForRemoteNotifications()
//UIApplication.shared.registerForRemoteNotifications()
}
Then the register and fail method:
private func application(application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
Messaging.messaging().apnsToken = deviceToken as Data
print("Registered Notification")
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print(error.localizedDescription)
print("Not registered notification")
}
Note:
- I have tried it on real device not neither of the methods are getting called.
- I have tried on simulator if the code is working or not, didFailToRegisterForRemoteNotificationsWithError is getting called with error.(Which means code is fine)
- I have double checked the certificates and regenerated the provisioning file after turning on the push notifications in capabilities.
- I have also added background modes -> remote notifications on.
- I have tried with legacy build also no luck.
- I have tried reinstalling apps many times not working.
- FirebaseAppDelegateProxyEnabled is set to NO in plist still no luck.
- Also updated the pods still no luck.