푸시 메시지 연동
1
2




3
class AppDelegate: NSObject, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
) -> Bool {
return true
}
}#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@end- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return YES;
}import SwiftUI
@main
struct sampleApp: App {
...
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
...
}4
import Hackle
class AppDelegate: NSObject, UIApplicationDelegate {
...
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// iOS 앱에서 푸시 권한 요청
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: { _, _ in }
)
UNUserNotificationCenter.current().delegate = self
application.registerForRemoteNotifications()
// 핵클 SDK 초기화
Hackle.initialize(sdkKey: YOUR_APP_SDK_KEY)
return true
}
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
// 핵클 서버로 APNs 푸시 토큰 전달
Hackle.app()?.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()
}
}actionType
설명
7
8
핵클 환경
APNs Environment
빌드 환경
딥링크 이동
import SwiftUI
@main
struct sampleApp: App {
...
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL(perform: { url in
// Handle opened url
print("\(url.absoluteString) opened.")
})
}
}
...
}class AppDelegate: NSObject, UIApplicationDelegate {
...
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:] ) -> Bool {
// Handle opened url
print("\(url.absoluteString) opened.")
}
...
}마지막 업데이트