Search
Duplicate

7. Push Notification 연동

iOS의 경우 APNS에 대한 연동을 지원합니다. APNS를 통한 Push Notification 연동을 희망하는 경우 담당자에게 문의하세요.
APNS의 경우 .p8 형식의 인증서만 지원합니다.

Push Notification 세팅

사용하는 Push Service에 따라 다음의 절차를 수행하세요
1.
APNS에서 .p8 인증서를 다운로드 하세요.
2.
BuzzBooster Dashboard에서 서비스에 맞게 폼을 입력하세요.
3.
정보를 입력한 뒤 아래 Push Test를 통해서 정상적으로 동작하는지 확인할 수 있습니다.

Push Notification 설정

1. UNUserNotificationCenter, Remote Notification 설청

Notification 처리를 위해 AppDelegate를 UNUserNotificationCenter의 delegate으로 설정하고 권한을 획득 합니다. 그 이후 Application을 Remote Notification 서비스에 등록합니다.
AppDelegate.swift
func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { UNUserNotificationCenter.current().delegate = self var options: UNAuthorizationOptions = [.alert, .sound, .badge] UNUserNotificationCenter.current().requestAuthorization(options: options) { _ in } UIApplication.shared.registerForRemoteNotifications() }
Swift
복사

2. Device Token을 SDK에 세팅하기

Device Token으로 Push Notification을 전송하기 위해 Token을 SDK에 세팅하세요.
AppDelegate.swift
func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data ) { BuzzBooster.setDeviceToken(deviceToken) }
Swift
복사

3. Notification 처리하기

UNUserNotificationCenterDelegate을 채택하여 다음과 같이 구현하세요.
AppDelegate.swift
extension AppDelegate: UNUserNotificationCenterDelegate { func userNotificationCenter( _ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void ) { // Notification이 수신 됐을 때 처리를 BuzzBooster SDK로 위임하세요. // 이 때, BuzzBooster SDK는 BuzzBooster와 관련된 Notification만 처리합니다. let userInfo = response.notification.request.content.userInfo if (userInfo["BuzzBooster"] != nil) { BuzzBooster.userNotificationCenter( center, didReceive: response, withCompletionHandler: completionHandler ) } else { // enter your code } } func userNotificationCenter( _ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void ) { // App이 Foreground인 상태에서 Notification을 보여주려면 다음과 같이 처리하세요. completionHandler([.alert, .sound]) } }
Swift
복사