Next, let's embed our images. First, return to the RestaurantDetailViewController.swift file and, in the showNotification() method we created, remove the following code:
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let identifier = "letsEatReservation"
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: { error in
// handle error
})
Replace the deleted section of code with the following code:
do {
let url = Bundle.main.url(forResource: "sample-restaurant-img@3x", withExtension: "png")
if let imgURL = url {
let attachment = try UNNotificationAttachment(identifier: "letsEatReservation", url: imgURL, options: nil)
content.attachments = [attachment]
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let identifier = "letsEatReservation"
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: { error in
// handle error
})
}
}
catch {
print("there was an error with the notification")
}
In this do...catch, we are getting the image URL from our project and creating an attachment. We attach the rich media (here, an image) to the notification. The rest of the code is what we removed and just added back inside of the do...catch.
Build and rerun the project by hitting the Play button (or using ⌘ + R). When you get to a restaurant detail page, tap the time button and wait five seconds. You should now see a thumbnail image in the notification:

Also, if you click and pull down on the notification, you should see the following:

Thus far, we have been receiving notifications while inside of the app. If you want to test notifications outside of the app, take the following steps. Build and run the project by hitting the Play button (or using ⌘ + R). When you get to a restaurant detail page, tap the time button and, then, immediately hit ⌘ + Shift + H. This takes you out of the app, and you will then see the following:

If you click and pull down on the notification, you will see the following :

Our notifications are looking good, but you really cannot do anything with them. It would be nice to confirm your reservation with a yes or no, for example. We need to add some buttons for the notifications to do this.