iOS 푸시 메시지 연동
1
2




3
4
import UIKit
import React
import React_RCTAppDelegate
import ReactAppDependencyProvider
import Hackle
@main
class AppDelegate: RCTAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
) -> Bool {
// 기존 구현된 코드 내에 추가
...
// iOS 앱에서 푸시 권한 요청
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
// Enable or disable features based on authorization.
}
notificationCenter.delegate = self
application.registerForRemoteNotifications()
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
// 핵클 서버로 APNs 푸시 토큰 전달
Hackle.setPushToken(deviceToken)
}
...
}5
import Hackle
extension AppDelegate: UNUserNotificationCenterDelegate {
// Foreground push message
func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions
) -> Void) {
if Hackle.userNotificationCenter(
center: center, willPresent: notification, withCompletionHandler: completionHandler
) {
// Succefully processed notification
// Automatically consumed completion handler
return
} else {
// Received not hackle notification or error
print("Do something")
if #available(iOS 14.0, *) {
completionHandler([.list, .banner])
} else {
completionHandler([.alert])
}
}
}
}6
import Hackle
extension AppDelegate: UNUserNotificationCenterDelegate {
// push click
public func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
if let _ = Hackle.handleNotification(response: response) {
// process hackle notification
} else {
// not hackle notification or error
print("do something")
}
// handleNotification 에서 completionHandler를 호출하지 않으니
// 핵클 푸시 여부에 관계없이 반드시 completionHandler를 호출해야 합니다.
completionHandler()
}
}7
8
핵클 환경
APNs Environment
빌드 환경
딥링크 이동
마지막 업데이트