> For the complete documentation index, see [llms.txt](https://docs.hackle.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hackle.io/en/development-guide/react-native/push-message/rn-ios-rich-push-message.md). Agents can also search and read this documentation through its [MCP server](https://docs.hackle.io/~gitbook/mcp).

# iOS Rich Push Message

To display Push Messages with images in an iOS app, add a [Notification Service Extension](https://developer.apple.com/documentation/usernotifications/unnotificationserviceextension).\
For details on iOS Rich Push Notifications, refer to [Rich Push Notification](https://developer.apple.com/documentation/usernotificationsui/customizing-the-appearance-of-notifications).

{% stepper %}
{% step %}

### Add Notification Service Extension to Your App

Open `ios/{APP_NAME}.xcworkspace` in Xcode, then select `Notification Service Extension` from `File → New → Target...`.

![](https://143363954-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyAVlNQhS253reum0Ce94%2Fuploads%2Fgit-blob-c0eead54b25a65af31bbf343000b55845fc2036f%2F0466631-image_3e7be97c84fa7368.png?alt=media)

Enter an appropriate name and click `Finish`.

![](https://143363954-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyAVlNQhS253reum0Ce94%2Fuploads%2Fgit-blob-9de73631a42f1ea0b2a1b0d0d221de70068756d3%2F02635c3-Screenshot_2024-01-09_at_3.35.10_7ce9d38c46307e16.png?alt=media)
{% endstep %}

{% step %}

### Add HackleNotificationService to the Extension

{% tabs %}
{% tab title="Integration" %}
In Xcode, select `File → Add Package Dependencies...` and add the package below.

* Package URL: `https://github.com/hackle-io/hackle-ios-sdk.git`
* Dependency Rule: `Up to Next Major Version`, `4.4.0`

On the screen for adding package products to a target, add only `HackleNotificationService` to the Extension target you created earlier.

If the package has already been added or you did not specify the Extension target, add `HackleNotificationService` from `General → Frameworks and Libraries → +` of the Extension target.

![](https://143363954-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyAVlNQhS253reum0Ce94%2Fuploads%2Fgit-blob-20f7ef125325c03a4918e50bc634e72bf4dccf75%2Fios-rich-push-select-hackle-notification-service.png?alt=media)
{% endtab %}

{% tab title="Migrating from CocoaPods" %}
In React Native SDK 4.2.0 and above, the Extension is integrated as a Swift Package. If you previously integrated it with CocoaPods, remove the Extension target below from `ios/Podfile`.

{% code title="ios/Podfile" %}

```ruby
# Remove
target 'NotificationServiceExtension' do
  pod 'Hackle'
end
```

{% endcode %}

Run the following command in the `ios` directory to clean up the existing linkage.

```shell
pod install
```

{% hint style="warning" %}
If `libPods-<target>.a` still remains in `General → Frameworks and Libraries` of the Extension target after `pod install`,\
select the item and remove it with the `-` button.
{% endhint %}

![](https://143363954-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyAVlNQhS253reum0Ce94%2Fuploads%2Fgit-blob-a15a81ac573d9598e7d608e96d6fb5ef7aaaccb3%2Fios-rich-push-extension-libpods.png?alt=media)

Next, add `HackleNotificationService` to the Extension target.

In Xcode, select `File → Add Package Dependencies...` and add the package below.

* Package URL: `https://github.com/hackle-io/hackle-ios-sdk.git`
* Dependency Rule: `Up to Next Major Version`, `4.4.0`

On the screen for adding package products to a target, add only `HackleNotificationService` to the Extension target you created earlier.

If the package has already been added or you did not specify the Extension target, add `HackleNotificationService` from `General → Frameworks and Libraries → +` of the Extension target.

![](https://143363954-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyAVlNQhS253reum0Ce94%2Fuploads%2Fgit-blob-20f7ef125325c03a4918e50bc634e72bf4dccf75%2Fios-rich-push-select-hackle-notification-service.png?alt=media)
{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}

### Configure Minimum Deployments

**Set the Extension's `Minimum Deployments` to match the app.**

{% hint style="danger" %}
If the minimum supported version differs between the app and the Extension, images may not be displayed depending on the iOS version.
{% endhint %}

![](https://143363954-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyAVlNQhS253reum0Ce94%2Fuploads%2Fgit-blob-889981100926f46aaa176f97867ade1bab724e92%2F29560c928d45f4b7f541953778d9df7a81a523e7_0592d9eab2f8c6dc.png?alt=media)
{% endstep %}

{% step %}

### Add Images to Push Messages

Add `HackleNotificationService.handleRichNotification` to the `didReceive` function in the Extension's `NotificationService`.\
If you migrated from CocoaPods, replace the existing `import Hackle` with `import HackleNotificationService`.

{% code title="NotificationService.swift" %}

```swift
import UserNotifications
import HackleNotificationService

class NotificationService: UNNotificationServiceExtension {

    var defaultNotificationContent: UNNotificationContent?
    var contentHandler: ((UNNotificationContent) -> Void)?

    override func didReceive(
      _ request: UNNotificationRequest,
      withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void
    ) {
        self.defaultNotificationContent = request.content
        self.contentHandler = contentHandler

        if HackleNotificationService.handleRichNotification(request: request, contentHandler: contentHandler) {
            return
        }

        contentHandler(request.content)
    }

    override func serviceExtensionTimeWillExpire() {
      if let contentHandler = contentHandler,
         let defaultNotificationContent = defaultNotificationContent {
            contentHandler(defaultNotificationContent)
        }
    }
}
```

{% endcode %}

If the push was not sent by Hackle, `handleRichNotification` returns `false`.\
In that case, call `contentHandler` with the received content as is.
{% endstep %}
{% endstepper %}

{% hint style="info" %}
After building, check that the Extension is included in `PlugIns/<Extension name>.appex` of the app bundle.\
Verify image attachments with real pushes on a physical device.\
Pushes sent with `xcrun simctl push` on the simulator do not run the Notification Service Extension, so images are not attached.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.hackle.io/en/development-guide/react-native/push-message/rn-ios-rich-push-message.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
