Поэтому я пытался добавить уведомление в новый центр UNUserNotificationCenter, но, похоже, я его не получаю.
У моего контроллера просмотра есть действие:
@IBAction func sendPressed(_ sender: AnyObject) {
let content = UNMutableNotificationContent()
content.title = "Hello"
content.body = "What up?"
content.sound = UNNotificationSound.default()
// Deliver the notification in five seconds.
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 5, repeats: false)
let request = UNNotificationRequest.init(identifier: "FiveSecond", content: content, trigger: trigger)
// Schedule the notification.
let center = UNUserNotificationCenter.current()
center.add(request) { (error) in
print(error)
}
print("should have been added")
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let center = UNUserNotificationCenter.current()
center.requestAuthorization([.alert, .sound]) { (granted, error) in
}
}
И у меня в проекте тоже есть Notification Content Extension
, но, похоже, он вообще не запущен, есть идеи, что мне не хватает? Я пытаюсь привести пример из пользовательской документации, но он ничего не говорит мне, или я пропустил его.
Здесь: https://developer.apple.com/reference/usernotifications/unmutablenotificationcontent
Также: https://developer.apple.com/reference/usernotificationsui https://developer.apple.com/reference/usernotifications
Изменить:
Так что приложение в фоновом режиме сделало свое дело.