我正在关注本教程:https ://medium.com/flawless-app-stories/ios-remote-push-notifications-in-a-nutshell-d05f5ccac252
但由于某种原因,我得到
无法将“AppDelegate”分配给“UNUserNotificationCenterDelegate”。
那条线有什么作用?如果我将其注释掉,其余代码将起作用,并且会提示用户是否要允许通知。
func registerForPushNotifications() {
UNUserNotificationCenter.current().delegate = self // line in question
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {
(granted, error) in
print("Permission granted: \(granted)")
// 1. Check if permission granted
guard granted else { return }
// 2. Attempt registration for remote notifications on the main thread
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
}