-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeymeApp.swift
77 lines (61 loc) · 2.32 KB
/
KeymeApp.swift
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
import SwiftUI
import UserNotifications
import ComposableArchitecture
import FirebaseCore
import FirebaseMessaging
import Features
import Network
import KakaoSDKAuth
import KakaoSDKCommon
@main
struct KeymeApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
let KAKAO_PRIVATE_KEY = "" // 🚨 SECRET 🚨
init() {
KakaoSDK.initSDK(appKey: KAKAO_PRIVATE_KEY)
}
var body: some Scene {
WindowGroup {
RootView()
}
}
}
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, _ in
guard granted else { return }
// 푸시토큰 애플 서버에 등록하기
UNUserNotificationCenter.current().getNotificationSettings { settings in
guard settings.authorizationStatus == .authorized else { return }
DispatchQueue.main.async {
application.registerForRemoteNotifications()
}
}
}
return true
}
func application(
_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]
) -> Bool {
if (AuthApi.isKakaoTalkLoginUrl(url)) {
return AuthController.handleOpenUrl(url: url)
}
return false
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
let token = tokenParts.joined()
Messaging.messaging().setAPNSToken(deviceToken, type: .unknown)
print("firebase Device Token: \(token)")
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("firebase Failed to register for remote notifications: \(error)")
}
}