---
title: "#261: Rich Notifications 💰💭"
url: https://littlebitesofcocoa.com/261-rich-notifications
author: Jake Marsh
date: 2016-09-08
published: 2016-09-08
topics: ["Notifications"]
description: "Today we'll continue our look at Notifications in iOS 10 by looking at the new \"rich\" attributes we can use to give our notifications titles, subtitles, and..."
---

# #261: Rich Notifications 💰💭

By Jake Marsh, September 8, 2016. HTML: https://littlebitesofcocoa.com/261-rich-notifications

Today we'll continue our look at [Notifications](https://www.littlebitesofcocoa.com/topics/29-notifications?v=l) in **iOS 10** by looking at the new "rich" attributes we can use to give our **notifications** titles, subtitles, and even media! Let's check it out.

Most of this code will center around our old friend `UNNotificationContent`:

``` swift
let notification = UNMutableNotificationContent()

notification.categoryIdentifier = "asteroid-detected"

notification.title = "Asteroid Detected! 🚀"
notification.body = "Collision imminent. Immediate action required!"
```

We're already using two new fields here: `title` and `body`. This allows us to properly highlight the important and extra information in our **notification's** UI:

<img src="https://media.littlebitesofcocoa.com/258-5.png" style="max-width: 374px;">

Nice.

Now, it'd be really great if we could show the user an image of the giant space rock they're hurdling towards. Let's attach some media to do this:

``` swift
if let attachment = try? UNNotificationAttachment(
  identifier: "asteroid-id-123-photo",
  url: asteroidImageURL
) {
  notification.attachments.append(attachment)
}
```

Heads up: That will need to be a local file URL, not a remote one.

Now, when our **notification** is shown, we see a nice little preview of the asteroid:

<img src="https://media.littlebitesofcocoa.com/258-7.png" style="max-width: 374px;" />

One small note here: The thumbnail image shown here is the result of adding padding manually to the image to account for the the system's aggressive cropping.

There is a way to pass a dictionary of options to `UNNotificationAttachement`. There's even a key called <i>UNNotificationAttachmentOptionsThumbnailClippingRectKey</i>.

This key requires a "normalized" `CGRect` describing how the **image** should be clipped.

Setting this key to `CGRect(x: 0, y: 0, width: 1, height: 1)` <i>should</i> allow the whole thing to be visible, but it seems the system ignores this value entirely as of **Beta 6**.

[OpenRadar #27708976](http://www.openradar.me/27708976), [rdar://27708976](rdar://27708976)

<p></p>
