> 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/development-guide/react-native/react-native-deeplink/react-native-deeplink-delegate.md).

# HackleDelegate로 링크 처리

`HackleDelegate`를 등록하면 SDK가 링크를 열지 않고 JavaScript로 넘겨줍니다.\
로그인 여부를 확인한 뒤 이동하는 것처럼 앱의 라우터나 화면 이동 로직으로 링크를 처리하고 싶을 때 사용합니다.

## SDK 초기화 전에 클릭한 푸시 링크

앱이 꺼진 상태에서 푸시 메시지를 클릭하면, JavaScript에서 SDK를 초기화하기 전에 링크가 도착합니다.

이 링크까지 delegate로 받으려면 아래 두 가지를 모두 설정합니다.

* 네이티브 설정으로 푸시 링크 처리를 SDK 초기화 이후로 미룹니다.
* `createInstance`의 `delegate`로 delegate를 등록합니다. `setDelegate`로 등록하면 이 링크를 받을 수 없습니다.

{% tabs %}
{% tab title="iOS" %}
`Info.plist`에 Boolean 값으로 추가합니다.\
String 타입으로 넣은 값은 무시됩니다.

{% code title="Info.plist" %}

```xml
<key>HackleDeferPushLinkUntilInitialized</key>
<true/>
```

{% endcode %}
{% endtab %}

{% tab title="Android" %}
`AndroidManifest.xml`의 `<application>` 안에 추가합니다.

{% code title="AndroidManifest.xml" %}

```xml
<meta-data
    android:name="io.hackle.android.defer_push_link_until_initialized"
    android:value="true" />
```

{% endcode %}
{% endtab %}
{% endtabs %}

<table><thead><tr><th width="200">값</th><th>동작</th></tr></thead><tbody><tr><td>설정 없음 또는 <code>false</code> (기본값)</td><td>SDK 초기화 전에 클릭한 푸시 링크를 SDK가 바로 열고 delegate에는 전달하지 않습니다.</td></tr><tr><td><code>true</code></td><td>링크를 보관했다가 SDK 초기화 후 한 번 전달합니다.<br>delegate가 등록되어 있으면 delegate로, 없으면 기본 동작으로 전달합니다.</td></tr></tbody></table>

## HackleDelegate 구현

`handleUrl`은 SDK가 링크를 열어야 할 때 호출됩니다.\
`channel`로 푸시 메시지 링크와 인앱 메시지 링크를 구분할 수 있습니다.

```typescript
import { Linking } from 'react-native';
import type { HackleDelegate } from '@hackler/react-native-sdk';

const appDelegate: HackleDelegate = {
  handleUrl({ url, channel }) {
    if (channel === 'PUSH') {
      console.log('push link:', url);
    } else {
      console.log('in-app message link:', url);
    }

    if (url.startsWith('myapp://')) {
      // 앱의 라우터로 링크를 처리합니다.
      AppRouter.route(url);
    } else {
      // 앱에서 처리하지 않는 http/https 링크는 브라우저로 엽니다.
      Linking.openURL(url);
    }
  },
};
```

`handleUrl`에서 발생한 에러는 SDK가 잡아서 로그로 남깁니다.

## delegate 등록

* 초기화 시점: `createInstance` 설정의 `delegate`로 등록합니다.
* 초기화 이후: `setDelegate`로 등록합니다.
* 해제: `setDelegate`에 `null`로 등록합니다.

```typescript
import { createInstance } from '@hackler/react-native-sdk';

// 초기화 시점에 등록
const hackleClient = createInstance('YOUR_APP_SDK_KEY', {
  delegate: appDelegate,
});

// 초기화 이후에 등록
await hackleClient.onReady();
hackleClient.setDelegate(appDelegate);

// 등록을 해제하면 SDK의 기본 링크 처리로 돌아갑니다.
hackleClient.setDelegate(null);
```

{% hint style="warning" %}
SDK 초기화가 끝나기 전에 호출한 `setDelegate`는 적용되지 않을 수 있습니다.\
앱 시작부터 링크를 받으려면 `createInstance`의 `delegate`로 등록하세요.
{% endhint %}

모든 클라이언트가 하나의 delegate를 공유하며, 마지막에 등록한 delegate가 링크를 받습니다.

## HackleUrlContext

`handleUrl`에 전달되는 `HackleUrlContext`의 속성입니다.

<table><thead><tr><th width="150">속성</th><th width="220">타입</th><th>설명</th></tr></thead><tbody><tr><td><code>url</code></td><td><code>string</code></td><td>푸시 메시지 또는 인앱 메시지에 설정한 링크입니다.<br>http/https 링크도 전달됩니다.</td></tr><tr><td><code>channel</code></td><td><code>HackleUrlChannel</code></td><td><p>링크가 전달된 경로입니다.</p><ul><li>푸시 메시지 클릭: <code>'PUSH'</code></li><li>인앱 메시지의 "링크 이동" 클릭 액션: <code>'IN_APP_MESSAGE'</code></li></ul></td></tr></tbody></table>


---

# 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/development-guide/react-native/react-native-deeplink/react-native-deeplink-delegate.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.
