I think the correct way to register for push notification is to configure the user interactions first then register for push notifications, as bellow
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in
if granted {
// Register with APNs
UIApplication.shared.registerForRemoteNotifications()
}else{
//user did't grant permissino: so we need to send phone ids, as we need to call this function every time the application opened
self.sendPhoneIdsToLookitServer()
}
}
but apple shows different way , it doesn't suggest to register for remote notification as callback after configuring user interactions rather it ask to configure user interactions and then register for push notification without waiting for user response, as you can see here
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Configure the user interactions first.
self.configureUserInteractions()
NSApplication.shared().registerForRemoteNotifications(matching: [.alert, .sound])
}
which approach is the correct one ?