# iOS 푸시 알림 원클릭 수신거부 구현 가이드 (category이용)

## 1. 개요

기존 핑거푸시의 기본 category 값은 "fp"입니다. \
앞으로  핑거푸시에서 메세지 발송 시 광고성 메세지 옵션을 On(광고 수신 동의자)으로  발송되는 메시지의 경우 payload의 항목 category 값이 “fp1”으로 설정되어 발송됩니다.

앱 내에서 fp1 카테고리에 대한 액션(수신거부 버튼)을 미리 등록하면, 사용자가 알림을 길게 누르거나 아래로 당겼을 때 수신거부 버튼이 노출할 수 있게 구현 가능합니다.

## 2. 주요 설정 내용

* **대상 카테고리:** fp1
* **추가 액션:** 수신거부 (Unsubscribe)
* &#x20;**작동 방식:** 사용자가 수신거부  버튼 클릭 시 별도의 앱 실행이 실행 되면서 핑거푸시 SDK내의 광고수신 동의 설정 API requestSetAdPushEnable 호출

## 3. 단계별 구현 방법 예제

**1) 알림 카테고리 및 액션 등록**\
AppDelegate 또는 알림 관리를 담당하는 클래스에서 UNNotificationCategory를 등록해야 합니다.\
fp1이라는 식별자를 가진 카테고리에 '수신거부' 액션을 추가합니다.

```
//Swift
import UserNotifications

func registerNotificationCategories() {
    // 1. 수신거부 버튼(액션) 정의
    let unsubscribeAction = UNNotificationAction(
        identifier: "UNSUBSCRIBE_ACTION",
        title: "원클릭 수신거부",
        options: [.authenticationRequired, .destructive] // 인증 필요 및 붉은색 표시(선택)
    )

    // 2. "fp1" 카테고리에 액션 등록
    let adCategory = UNNotificationCategory(
        identifier: "fp1",
        actions: [unsubscribeAction],
        intentIdentifiers: [],
        options: .customDismissAction
    )

    // 3. 시스템에 카테고리 등록
    UNUserNotificationCenter.current().setNotificationCategories([adCategory])
}
```

**2) 액션 이벤트 처리 (수신거부 로직)**\
사용자가 '원클릭 수신거부' 버튼을 눌렀을 때 실행될 로직을 작성합니다. \
이 시점에 핑거푸시 API 또는 귀사의 수신거부 처리 서버 API를 호출해야 합니다.

```
//Swift
extension AppDelegate: UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler: @escaping () -> Void) {
        
        // 사용자가 누른 액션의 식별자 확인
        if response.actionIdentifier == "UNSUBSCRIBE_ACTION" {
            // TODO: 핑거푸시 수신거부 API 호출 
        finger.sharedData()?.requestSetAdPushEnable(false, { (posts, error) -> Void in
          
        })
        
            print("사용자가 수신거부를 선택했습니다.")
        }
        
        completionHandler()
    }
}
```

**3) 예시 이미지**

<figure><img src="/files/wbnumPjgI6QrEfIDcc0e" alt=""><figcaption></figcaption></figure>

## 4. APNs 페이로드 예시

핑거푸시 서버에서 광고성 메시지 발송 시 전달되는 페이로드 구조는 다음과 같습니다.

```
//JSON
{
    "aps": {
        "alert": {
            "title": "(광고) 특별 할인 안내",
            "body": "지금 바로 확인해보세요!"
        },
        "category": "fp1",
        "mutable-content": 1,
        sound = default
    },
    code = "CD:0;IM:1;WL:1;PT:DEFT",
    msgTag = 53,
    src = fp,
    labelCode = "",
    weblink = "http://www.fingerpush.com/"
    ....
}
```

## 5. 주의사항

* **카테고리 매칭:** 반드시 category 값이 fp1인 경우에만 해당 버튼이 노출됩니다. 기존 fp 값인 경우에는 일반 노티피케이션으로 동작합니다.
* **버튼 노출:** iOS 정책상 알림을 롱터치(3D Touch)하거나 하단으로 드래그해야 버튼이 노출될 수 있습니다.
* **API 연동:** 수신거부 버튼 클릭 시 반드시 실제 수신거부 처리가 서버(핑거푸시 DB)에 반영되도록 광고수신거부API(requestSetAdPushEnable) 연동을 완료해 주세요.

**도움이 필요하신가요?** 구현 중 문의사항이 있으시면 핑거푸시 QnA 게시판으로 문의 주시면 빠르게 답변드리겠습니다.


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.fingerpush.com/app-push/sdk-manual/ios/unsubscribe.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
