request authorization for push notifications always return false when app is first loaded even user tap "allow" on dialog.
Here is function for register which is called in didFinishLaunchingWithOptions. At next launch granted is true.
func registerForPushNotifications() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {
(granted, error) in
print("Permission granted: \(granted)")
guard granted else{return}
self.getNotificationSettings()
}
}
Run Code Online (Sandbox Code Playgroud)