I'm trying to send a local notification after some time (e.g. 10 seconds). I want to add an image to the notification from xcassets but the imageURL
is always nil
.
I've tried creating a Path and then a URL from that path. I've also tried creating a url with the forResource
argument = nil
so that it finds ANY image with "png"
as the extension and still - nil
.
let content = UNMutableNotificationContent()
content.title = "Notification title"
content.subtitle = "notification subtitle"
content.body = "notification body"
let imageName = "delete"
guard let imageURL = Bundle.main.url(forResource: imageName, withExtension: "png") else {return}
let attachment = try! UNNotificationAttachment(identifier: imageName, url: imageURL, options: .none)
content.attachments = [attachment]
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 10, repeats: false)
let request = UNNotificationRequest(identifier: "notification.id.01", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
I've added print
statements to see what happens and I have confirmed that my method returns at the guard
statement.