您只需导入
UserNotifications
import UserNotifications
此外,确保您符合
UNUserNotificationCenterDelegate
作为一种良好的做法,我建议将其作为
extension
:
如果你不熟悉
代表团
,您可能需要检查
this
import UIKit
// add this:
import UserNotifications
class ViewController: UIViewController {
.
.
.
// somewhere in your code:
UNUserNotificationCenter.current().delegate = delegateObject
}
// add this:
// MARK:- UserNotifications
extension ViewController: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
{
completionHandler([.alert, .badge, .sound])
}
}