Я пытаюсь добавить пользовательское локальное уведомление, но я получаю только стандартное уведомление с моим действием:
Моя раскадровка выглядит так (стандартный шаблон):
У меня есть расширение, для которого UNNotificationExtensionCategory
установлено значение awesomeNotification
(в Info.plist). Также в основе этого расширения лежит шаблон Notification Content
от iOS - Application Extension
.
В моем делегате приложения у меня есть это:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let center = UNUserNotificationCenter.current()
let actions = [UNNotificationAction.init(identifier: "Hey", title: "Yo", options: UNNotificationActionOptions.foreground)]
let category = UNNotificationCategory(identifier: "awesomeNotification", actions: actions, minimalActions: actions, intentIdentifiers: [], options: [])
center.setNotificationCategories([category])
center.requestAuthorization([.alert, .sound]) { (granted, error) in
}
return true
}
В моем контроллере просмотра в основном приложении у меня есть следующее действие для его запуска:
@IBAction func sendPressed(_ sender: AnyObject) {
let content = UNMutableNotificationContent()
content.categoryIdentifier = "awesomeNotification"
content.title = "Hello"
content.body = "What up?"
content.sound = UNNotificationSound.default()
// Deliver the notification in five seconds.
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(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")
}
Изменить
Так что это работает на iPhone 6s/6s+, очень странное поведение: