Добавить локальное уведомление в iOS 10 - Swift 3

Поэтому я пытался добавить уведомление в новый центр 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

Редактировать:

Так что приложение в фоновом режиме сделало свое дело.

Ответы на вопрос(5)

Ваш ответ на вопрос