我想爲推送通知登記正確的方法是先配置的用戶交互,然後註冊推送通知,如波紋管如何註冊推送通知? 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,你可以看看下面我的答案 –