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

# HackleDelegate로 링크 처리

{% hint style="info" %}
iOS SDK 4.4.0 버전 이상에서 지원하는 기능입니다.
{% endhint %}

`HackleDelegate`를 등록하면 SDK가 링크를 열지 않고 앱에 넘겨줍니다.\
로그인 여부를 확인한 뒤 이동하는 것처럼 앱의 흐름에 맞춰 링크를 처리할 수 있습니다.

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

`Info.plist`에 아래 옵션을 추가하면 푸시 클릭 링크 처리를 SDK 초기화 이후로 지연시킬 수 있습니다.

{% hint style="warning" %}
기본값에서는 SDK 초기화 전에 탭한 푸시 링크가 delegate로 오지 않습니다.\
이 링크까지 delegate로 받으려면 값을 boolean `YES`로 설정하고, `HackleConfigBuilder`의 `delegate`로 초기화할 때 delegate를 함께 등록하세요.
{% endhint %}

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

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

## HackleDelegate 구현

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

{% tabs %}
{% tab title="Swift" %}

```swift
import Hackle

class AppRouter: HackleDelegate {

    @MainActor
    func handleURL(_ context: HackleURLContext) {
        switch context.channel {
        case .push:
            print("push link: \(context.url)")
        case .inAppMessage:
            print("in-app message link: \(context.url)")
        }
        // 앱의 라우터로 context.url을 처리합니다.
    }
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
@import Hackle;

@interface AppRouter : NSObject <HackleDelegate>
@end

@implementation AppRouter

- (void)handleURL:(HackleURLContext *)context {
    switch (context.channel) {
        case HackleURLChannelPush:
            NSLog(@"push link: %@", context.url);
            break;
        case HackleURLChannelInAppMessage:
            NSLog(@"in-app message link: %@", context.url);
            break;
    }
    // 앱의 라우터로 context.url을 처리합니다.
}

@end
```

{% endtab %}
{% endtabs %}

## delegate 등록

* 초기화 시점: `HackleConfigBuilder`의 `delegate`로 등록합니다.
* 초기화 이후: `Hackle.setDelegate`로 등록합니다.
* 해제: `Hackle.setDelegate`에 `nil`을 넘깁니다.

{% tabs %}
{% tab title="Swift" %}

```swift
// 초기화 시점에 등록
let config = HackleConfigBuilder()
    .delegate(AppRouter())
    .build()

Hackle.initialize(sdkKey: YOUR_APP_SDK_KEY, config: config) {
    // SDK ready to use.
}

// 초기화 이후에 등록
Hackle.setDelegate(AppRouter())

// 등록 해제
Hackle.setDelegate(nil)
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
// 초기화 시점에 등록
HackleConfigBuilder *builder = [[HackleConfigBuilder alloc] init];
[builder delegate:[[AppRouter alloc] init]];
HackleConfig *config = [builder build];

[Hackle initializeWithSdkKey:@"YOUR_APP_SDK_KEY" config:config completion:^{
    // SDK ready to use.
}];

// 초기화 이후에 등록
[Hackle setDelegate:[[AppRouter alloc] init]];

// 등록 해제
[Hackle setDelegate:nil];
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
SDK 초기화 전에 `Hackle.setDelegate`를 호출하면 무시됩니다.\
초기화 전부터 링크를 받으려면 `HackleConfigBuilder`의 `delegate`로 등록하세요.
{% endhint %}

## HackleURLContext

`handleURL`로 전달되는 `HackleURLContext`의 속성입니다.

<table><thead><tr><th width="160">속성</th><th width="220">타입</th><th>설명</th></tr></thead><tbody><tr><td><code>url</code></td><td><code>URL</code></td><td>푸시 메시지 또는 인앱 메시지에 설정한 링크</td></tr><tr><td><code>channel</code></td><td><code>HackleURLChannel</code></td><td><p>링크가 전달된 경로입니다.</p><ul><li>푸시 메시지: <code>.push</code>(ObjC: <code>HackleURLChannelPush</code>)</li><li>인앱 메시지: <code>.inAppMessage</code>(ObjC: <code>HackleURLChannelInAppMessage</code>)</li></ul></td></tr></tbody></table>

## delegate 등록 전후 비교

<table><thead><tr><th width="160">구분</th><th>delegate 미등록</th><th>delegate 등록</th></tr></thead><tbody><tr><td>링크 처리 주체</td><td>SDK</td><td>앱</td></tr><tr><td>딥링크</td><td>SDK가 <code>UIApplication.open</code>으로 열기</td><td><code>handleURL</code>로 전달</td></tr><tr><td>http/https 링크</td><td>Associated Domains와 일치하면 Universal Link로 전달하고 일치하지 않으면 <code>UIApplication.open</code>으로 열기</td><td><code>handleURL</code>로 전달</td></tr><tr><td>링크 전달 위치</td><td><a href="https://docs.hackle.io/development-guide/ios/ios-deeplink/ios-deeplink-os.md#handle-delivered-link">OS가 앱에 링크를 전달하는 메서드</a></td><td><code>handleURL</code></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/ios/ios-deeplink/ios-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.
