-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppDelegate.swift
More file actions
104 lines (93 loc) · 3.4 KB
/
AppDelegate.swift
File metadata and controls
104 lines (93 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright © 2025 Booket. All rights reserved
import BKCore
import BKData
import BKStorage
import Combine
import Firebase
import FirebaseMessaging
import KakaoSDKCommon
#if DEBUG
import Pulse
import PulseProxy
#endif
import UIKit
@main
final class AppDelegate: UIResponder, UIApplicationDelegate {
private var cancellables = Set<AnyCancellable>()
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
guard let kakaoAPIkey = Bundle.main.object(forInfoDictionaryKey: "KAKAO_NATIVE_APP_KEY") as? String else {
fatalError("Error: KAKAO_NATIVE_APP_KEY not found in Info.plist")
}
#if DEBUG
NetworkLogger.enableProxy()
LoggingBootstrap.install()
#endif
KakaoSDK.initSDK(appKey: kakaoAPIkey)
FirebaseApp.configure()
GAManager.configureAnalytics()
UNUserNotificationCenter.current().delegate = self
Messaging.messaging().delegate = self
// 앱 실행 시 DeviceID 생성 (없으면)
// 키체인에 저장되므로 앱 삭제 후 재설치해도 유지됨
KeychainDeviceIDStore.shared.getOrCreate()
.sink(
receiveCompletion: { completion in
if case .failure(let error) = completion {
AppLogger.auth.error("Failed to get or create device ID: \(error)")
}
},
receiveValue: { deviceID in
AppLogger.auth.info("Device ID ready: \(deviceID)")
}
)
.store(in: &cancellables)
return true
}
func application(
_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions
) -> UISceneConfiguration {
return UISceneConfiguration(
name: "Default Configuration",
sessionRole: connectingSceneSession.role
)
}
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
Messaging.messaging().apnsToken = deviceToken
}
/// 정확히 이 시점에서 FCM Token이 생성됩니다.
/// FCM Token이 재발급 되는 시점도 해당 시점입니다.
func messaging(
_ messaging: Messaging,
didReceiveRegistrationToken fcmToken: String?
) {
guard let token = fcmToken else { return }
KeychainPushTokenStore.shared.save(fcmToken: token)
.sink(
receiveCompletion: { completion in
if case .failure(let error) = completion {
AppLogger.auth.error("Failed to save FCM token: \(error)")
}
},
receiveValue: { _ in
AppLogger.auth.info("FCM token saved successfully")
}
)
.store(in: &cancellables)
}
func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
) {
completionHandler([.banner, .list, .sound])
}
}
extension AppDelegate: UNUserNotificationCenterDelegate, MessagingDelegate {}