Код: Выделить всё
Button(action: {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound], completionHandler: { granted, error in
Logger().log("Granted: \(granted)")
})
}, label: { Text("request") })
Button(action: {
UNUserNotificationCenter.current().delegate = delegate
let content = UNMutableNotificationContent()
// content.title = "title" // All works as expected with a notification title
content.sound = .default
for seconds in 3...5 {
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: Double(seconds), repeats: false)
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request)
}
}, label: { Text("click") })
Код: Выделить всё
class UserNotificationCenterDelegate: NSObject, UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
completionHandler()
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.sound, .list, .banner])
}
}
Подробнее здесь: https://stackoverflow.com/questions/785 ... background