我想为推送通知登记正确的方法是先配置的用户交互,然后注册推送通知,如波纹管如何注册推送通知? ios10
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()
}
}
但苹果表现出不同的方式,它不建议用于远程寄存器通知作为配置的用户交互,而要求它配置的用户交互,然后注册推送通知,而无需等待用户的响应,你可以看到here
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Configure the user interactions first.
self.configureUserInteractions()
NSApplication.shared().registerForRemoteNotifications(matching: [.alert, .sound])
}
哪一种方法是正确的后回调?
这详细解释:HTTP ://stackoverflow.com/a/40430122/3882338 –
@david,你可以看看下面我的答案 –