> 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-push-message.md). Agents can also search and read this documentation through its [MCP server](https://docs.hackle.io/~gitbook/mcp).

# iOS Push Message Integration

Integrate APNs with the Hackle SDK to receive Hackle Push Messages in your React Native iOS app.

{% hint style="info" %}
**Can be used alongside other push solutions**

To use alongside another push solution, disable the Swizzling option of the other push solution.\
Then refer to that solution's guide to configure push notification handling manually.
{% endhint %}

{% hint style="danger" %}
iOS Push Messages via FCM are not supported.\
To use iOS Push Messages, integrate with APNs.
{% endhint %}

{% stepper %}
{% step %}

### Configure APNs

To use Push Messages in your iOS app, you need to integrate your Hackle Workspace with APNs.

{% content-ref url="/pages/BOT7gk5BdiuJrp06YkoD" %}
[Apple Push Notification Service (APNs) Integration](https://docs.hackle.io/en/external-link/crm-channels/apple-push-notification-service-integration.md)
{% endcontent-ref %}
{% endstep %}

{% step %}

### Add Push Notifications Capability to Your App

Open `ios/{APP_NAME}.xcworkspace` in Xcode and click `+ Capability` in the `Signing & Capabilities` tab of the app target.

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

Add `Push Notifications` and `Background Modes`.

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

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

Enable `Remote notifications` under `Background Modes`.

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

{% step %}

### Collect Push Token

{% hint style="warning" %}
On iOS, push tokens are not collected automatically.\
You must pass the push token to Hackle with the code below to receive pushes.
{% endhint %}

Add the Hackle code below to your app's `AppDelegate`.

`Hackle.setPushToken` is a static method.\
The token is delivered even if you call it before the Hackle SDK is initialized in JavaScript.

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

```swift
import UserNotifications
import Hackle

class AppDelegate: ... {
  func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
  ) -> Bool {
    ...

    // Request push permission and register for remote notifications
    UNUserNotificationCenter.current().requestAuthorization(
      options: [.alert, .badge, .sound],
      completionHandler: { _, _ in }
    )
    UNUserNotificationCenter.current().delegate = self
    application.registerForRemoteNotifications()

    ...
  }

  func application(
    _ application: UIApplication,
    didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
  ) {
    // Pass the APNs push token to Hackle
    Hackle.setPushToken(deviceToken)
  }
}
```

{% endcode %}
{% endstep %}

{% step %}

### Display Push Messages

When the app is in the background, pushes are displayed without additional code.\
To display pushes while the app is in the foreground, add `userNotificationCenter(_:willPresent:withCompletionHandler:)`.

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

```swift
extension AppDelegate: UNUserNotificationCenterDelegate {
  // Display Push Messages in the foreground
  func userNotificationCenter(
    _ center: UNUserNotificationCenter,
    willPresent notification: UNNotification,
    withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
  ) {
    if Hackle.userNotificationCenter(
      center: center, willPresent: notification, withCompletionHandler: completionHandler
    ) {
      // For Hackle pushes, the SDK calls completionHandler.
      return
    }

    // Handle non-Hackle pushes in the app.
    completionHandler([.list, .banner])
  }
}
```

{% endcode %}

Returns `false` if the push was not sent by Hackle.
{% endstep %}

{% step %}

### Handle Push Clicks

{% hint style="danger" %}
If you do not call the Hackle push click handling method, clicking a push does not navigate to the link.\
Push click events are also not collected, so the push click-through rate metric is not available.
{% endhint %}

Add `userNotificationCenter(_:didReceive:withCompletionHandler:)` and call `Hackle.handleNotification`.

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

```swift
extension AppDelegate: UNUserNotificationCenterDelegate {
  ...

  // Push click
  func userNotificationCenter(
    _ center: UNUserNotificationCenter,
    didReceive response: UNNotificationResponse,
    withCompletionHandler completionHandler: @escaping () -> Void
  ) {
    if Hackle.handleNotification(response: response) == nil {
      // Handle non-Hackle pushes in the app.
    }

    // handleNotification does not call completionHandler.
    completionHandler()
  }
}
```

{% endcode %}

`Hackle.handleNotification` checks whether the push was sent by Hackle.\
For Hackle pushes, it sends the push click event to the Hackle server and handles the link configured in the push.\
Returns `nil` if the push was not sent by Hackle.
{% endstep %}

{% step %}

### Test Push Messages

**Verify Token**

* You can verify the token configured on an iOS device through [User Explorer](https://docs.hackle.io/en/development-guide/react-native/react-native-user-explorer.md).
* You can verify the iOS push token assigned to a specific user through [User Profile](https://docs.hackle.io/en/user-view/user-profile.md).

**Test Sending**

* Refer to the [Push Message Test Send Guide](https://docs.hackle.io/en/crm-marketing/push-message-guide/create-campaign.md#id-3-1) to verify Push Messages on an iOS device.
  {% endstep %}

{% step %}

### Receive Push Messages

{% hint style="info" %}
Even if the APNs Key Environment is set to `Sandbox & Production`, the scope of push message reception differs by Hackle environment and app build environment as shown below.
{% endhint %}

<table><thead><tr><th width="175.78125">Hackle Environment</th><th width="175.40625">APNs Environment</th><th>Build Environment</th></tr></thead><tbody><tr><td>Development Environment,<br>Development/Production test push</td><td>Sandbox</td><td>Direct run from Xcode,<br>Development provisioning</td></tr><tr><td>Production Environment</td><td>Production</td><td>TestFlight, Ad Hoc,<br>App Store distribution</td></tr></tbody></table>
{% endstep %}
{% endstepper %}

## Deep Link Navigation

For handling links when a Push Message is clicked, see [Deep Links](https://docs.hackle.io/en/development-guide/react-native/react-native-deeplink.md).


---

# 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-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.
