iOS 푸시 메시지 연동
1
2




3
4
import Flutter
import Hackle
import UIKit
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
...
// 기존 구현된 코드 내에 추가
// iOS 앱에서 푸시 권한 요청
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: { _, _ in }
)
NUserNotificationCenter.current().delegate = self
application.registerForRemoteNotifications()
...
}
override func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
// 핵클 서버로 APNs 푸시 토큰 전달
Hackle.setPushToken(deviceToken)
}
}5
import Flutter
import Hackle
import UIKit
@main
@objc class AppDelegate: FlutterAppDelegate {
...
// 기존 구현된 코드 내에 추가
// Foreground push message
override 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 Flutter
import Hackle
import UIKit
@main
@objc class AppDelegate: FlutterAppDelegate {
...
// 기존 구현된 코드 내에 추가
// push click
override 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
빌드 환경
딥링크 이동
마지막 업데이트