Мне нужно добавить картинку к уведомлениям, отправленным через Центр UNUserNotificationCenter. Я делаю как в руководстве, но уведомление приходит без изображения.
func scheduleNotification() {
let identifier = UUID().uuidString
let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
content.title = "Test notification"
content.body = "Message of test notification"
content.categoryIdentifier = self.notifyCategoryIdentifier
content.userInfo = ["customData": "test"]
content.sound = UNNotificationSound.default
content.badge = 1
let url = URL(fileURLWithPath: Bundle.main.path(forResource: "image.png", ofType: nil)!)
do {
let attachment = try UNNotificationAttachment(identifier: identifier, url: url)
content.attachments = [attachment]
} catch {
print(error.localizedDescription)
}
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
center.add(request)
}