# iOS 리치 알림 연동

iOS 10부터 푸시 알림에 정적 또는 애니메이션 이미지, 동영상까지 첨부할 수 있습니다. 사용자가 알림을 세게 탭하면 알림에 바로 표시됩니다.

이 기능은 코딩이 거의 필요 없이 매우 간단하게 활성화할 수 있습니다. 함께 해보겠습니다!

## 1. Notification Service Extension 생성하기

먼저 [Notification Service Extension](https://developer.apple.com/reference/usernotifications/unnotificationserviceextension)을 생성합니다. 이 extension은 사용자에게 표시될 콘텐츠를 다운로드합니다.

프로젝트에 새 타겟을 추가(File -> New -> Target)하고 _Notification Service Extension_을 생성합니다.

<img src="/ios-rich-notification-1.webp" alt="Notification Service Extension 생성"/>

<Aside type="caution">
 Notification Service Extension에는 별도의 Apple App ID와 Provisioning profile이 있습니다!

notification extension은 자체 Bundle Id(_예:_`com.pushwoosh.example.NotificationService`)와 별도의 **Apple App ID** 및 **Provisioning profile**을 가지며, 이는 Apple Developer Portal에서 별도로 설정해야 합니다.
</Aside>

## 2. Notification Service Extension 코드

이 코드는 첨부 파일을 다운로드하고 알림 콘텐츠 핸들러를 호출합니다.
extension에 그대로 복사하여 붙여넣기만 하면 됩니다.

<Tabs syncKey="code-example">
<TabItem label="Swift">
```swift
import UserNotifications
import PushwooshFramework

class NotificationService: UNNotificationServiceExtension {

    var contentHandler: ((UNNotificationContent) -> Void)?
    var bestAttemptContent: UNMutableNotificationContent?

    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        PWNotificationExtensionManager.shared().handle(request, contentHandler: contentHandler)
    }
}
```
</TabItem>

<TabItem label="Objective-C">
```objective-c
#import "PWNotificationExtensionManager.h"

@interface NotificationService : UNNotificationServiceExtension

@end

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    [[PWNotificationExtensionManager sharedManager] handleNotificationRequest:request contentHandler:contentHandler];
}

@end
```
</TabItem>
</Tabs>

## 3. 안전하지 않은 첨부 파일 URL 허용하기

Notification Service Extension은 별도의 바이너리이며 **자체 Info.plist** 파일이 있습니다.
**extension의 Info.plist** 파일에 **App Transport Security Settings**를 추가하고 **Allow Arbitrary Loads** 플래그를 `true`로 설정합니다.

**Info.plist**:
```xml
<key>NSAppTransportSecurity</key>
<dict>
	<key>NSAllowsArbitraryLoads</key>
	<true/>
</dict>
```

## 4. 리치 알림 보내기

리치 알림을 보내려면 **BANNER URL** 필드에 파일의 URL을 지정하기만 하면 됩니다.

<img src="/ios-rich-notification-2.webp" alt=""/>

Woosh! 알림을 세게 탭하면 모든 과정이 완료됩니다!

<video src="/ios-rich-notification-3.webm" title="예시" autoplay loop muted playsinline />

<Aside type="tip">
[iOS 리치 푸시 알림의 동영상을 force touch로 자동 재생하는 방법](/ko/developer/pushwoosh-sdk/ios-sdk/customizing-ios-sdk/#autoplay-a-video-sent-in-a-rich-notification-with-force-touch)에 대해 알아보세요.
</Aside>

## 피드백을 공유해주세요

여러분의 피드백은 더 나은 경험을 만드는 데 도움이 됩니다. SDK 연동 과정에서 문제가 발생하면 언제든지 알려주세요. 어려움이 있으시면 주저하지 마시고 [이 양식을 통해](https://docs.google.com/forms/d/e/1FAIpQLSd_0b8jwn-V_JmoPLIxIFYbHACCQhrzidOZV3ELywoQPXRSxw/viewform) 의견을 공유해주시기 바랍니다.