For the complete documentation index, see llms.txt. This page is also available as Markdown.

iOS Push Message Integration

Can be used alongside other push solutions

To use alongside another push solution, you must disable the Swizzling option of the other push solution.

After disabling Swizzling, refer to that solution's guide to configure push notification handling manually.

1

Configure APNs

To use push messages in your iOS app, you need to configure the integration between your Hackle workspace and APNs.

For details, refer to Apple Push Notification Service Setup.

2

Add PushNotification Capability to Your App

Open your project by opening the /ios/{APP_NAME}.xcworkspace file with Xcode, then click + Capability in the Signing & Capabilities tab of the project settings as shown below.

Add Push Notifications and Background Modes.

Then enable Remote notifications under Background Modes.

3

Configure AppDelegate

AppDelegate configuration is required to collect push tokens, display push messages, and handle push clicks.

Modifying AppDelegate is required for push message integration.

Open your project by opening the /ios/{APP_NAME}.xcworkspace file with Xcode, then open the AppDelegate file.

The AppDelegate file language differs depending on the React Native version.

  • React Native 0.77 and above: AppDelegate.swift

  • React Native 0.76 and below: AppDelegate.h & AppDelegate.mm

4

Collect Push Token

Add the setPushToken method to your AppDelegate as shown below.

import UIKit
import React
import React_RCTAppDelegate
import ReactAppDependencyProvider
import Hackle

@main
class AppDelegate: RCTAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
  ) -> Bool {
    // 기존 구현된 코드 내에 추가
    ...

    // iOS 앱에서 푸시 권한 요청
    let notificationCenter = UNUserNotificationCenter.current()
    notificationCenter.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
        // Enable or disable features based on authorization.
    }
    notificationCenter.delegate = self
    application.registerForRemoteNotifications()

    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }

  override func application(
    _ application: UIApplication,
    didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
  ) {
    // 핵클 서버로 APNs 푸시 토큰 전달
    Hackle.setPushToken(deviceToken)
  }
...
}
5

Display Push Messages

In the background, pushes are displayed automatically without any code implementation.

Add the userNotificationCenter method to display foreground push messages.

import Hackle

extension AppDelegate: UNUserNotificationCenterDelegate {
  // Foreground push message
  func userNotificationCenter(
    _ center: UNUserNotificationCenter,
    willPresent notification: UNNotification,
    withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions
  ) -> Void) {

    if Hackle.userNotificationCenter(
      center: center, willPresent: notification, withCompletionHandler: completionHandler
    ) {
      // Succefully processed notification
      // Automatically consumed completion handler
      return
    } else {
      // Received not hackle notification or error
      print("Do something")

      if #available(iOS 14.0, *) {
        completionHandler([.list, .banner])
      } else {
        completionHandler([.alert])
      }
    }
  }
}

Returns false if the push was not sent by Hackle.

6

Handle Push Clicks

Add the handleNotification method to handle push clicks.

import Hackle

extension AppDelegate: UNUserNotificationCenterDelegate {
  // push click
  public func userNotificationCenter(
    _ center: UNUserNotificationCenter,
    didReceive response: UNNotificationResponse,
    withCompletionHandler completionHandler: @escaping () -> Void
  ) {

    if let _ = Hackle.handleNotification(response: response) {
      // process hackle notification
    } else {
      // not hackle notification or error
      print("do something")
    }

    // handleNotification 에서 completionHandler를 호출하지 않으니
    // 핵클 푸시 여부에 관계없이 반드시 completionHandler를 호출해야 합니다.
    completionHandler()
  }
}

The push click function processes in the following order:

  1. Verify whether the push was sent by Hackle

  2. Send the push click event to the Hackle server

  3. (For deep link pushes) Handle the deep link

Returns nil if the push was not sent by Hackle.

7

Test Push Messages

Verify Token

Test

8

Push Message Reception

Whether push messages are received on iOS depends on the build environment.

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.

Hackle Environment
APNs Environment
Build Environment

Development environment, Development/Production test push

Sandbox

Direct run from Xcode, Development provisioning

Production environment

Production

TestFlight, Ad Hoc, App Store distribution

Hackle push messages support deep link navigation on click.

For information on how to use React Native deep links in an iOS environment, refer to the React Native Deep Link Guide.

Last updated