Я бы хотел использовать iOS local UNNotifications
, даже если мое приложение не запущено.Так же, как мы используем приложение Alarm in Clock.Мы можем настроить будильник, а затем выйти из приложения «Часы», но ... звук и уведомление будут запущены вовремя.Мне нужно такое же поведение.
Возможно ли это?
Отрывок моего кода:
import UIKit
import UserNotifications
class ViewController: UIViewController, UNUserNotificationCenterDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let content = UNMutableNotificationContent()
content.title = "Our title"
content.body = "A body of message"
UNUserNotificationCenter.current().delegate = self
content.sound = UNNotificationSound.default()
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: false)
let request = UNNotificationRequest(identifier: "testID", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
}
}