From b49bb562b2ca41ead12ac0f8a2cbe080b109b5cc Mon Sep 17 00:00:00 2001 From: leeyoonchae Date: Fri, 13 Sep 2024 11:40:38 +0900 Subject: [PATCH 1/5] build: add firebase --- Projects/App/DodamDodam.entitlements | 8 ++ Projects/App/Project.swift | 6 +- Tuist/Package.resolved | 117 +++++++++++++++++++++++++++ Tuist/Package.swift | 3 +- 4 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 Projects/App/DodamDodam.entitlements diff --git a/Projects/App/DodamDodam.entitlements b/Projects/App/DodamDodam.entitlements new file mode 100644 index 0000000..903def2 --- /dev/null +++ b/Projects/App/DodamDodam.entitlements @@ -0,0 +1,8 @@ + + + + + aps-environment + development + + diff --git a/Projects/App/Project.swift b/Projects/App/Project.swift index ab7b416..fd00716 100644 --- a/Projects/App/Project.swift +++ b/Projects/App/Project.swift @@ -6,7 +6,7 @@ let project = Project( options: .options( defaultKnownRegions: ["en", "ko"], developmentRegion: "ko" - ), + ), settings: .settings( base: .init(), configurations: [ @@ -39,7 +39,9 @@ let project = Project( .project(target: "Feature", path: .relativeToRoot("Projects/Feature")), .project(target: "Repository", path: .relativeToRoot("Projects/Data")), .project(target: "DIContainer", path: .relativeToRoot("Projects/DIContainer")), - .target(name: "DodamDodamWidget") + .target(name: "DodamDodamWidget"), + .external(name: "FirebaseAnalytics"), + .external(name: "FirebaseMessaging") ] ), .target( diff --git a/Tuist/Package.resolved b/Tuist/Package.resolved index 2c22bd3..75c56e5 100644 --- a/Tuist/Package.resolved +++ b/Tuist/Package.resolved @@ -1,5 +1,14 @@ { "pins" : [ + { + "identity" : "abseil-cpp-binary", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/abseil-cpp-binary.git", + "state" : { + "revision" : "194a6706acbd25e4ef639bcaddea16e8758a3e27", + "version" : "1.2024011602.0" + } + }, { "identity" : "alamofire", "kind" : "remoteSourceControl", @@ -9,6 +18,15 @@ "version" : "5.9.1" } }, + { + "identity" : "app-check", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/app-check.git", + "state" : { + "revision" : "3b62f154d00019ae29a71e9738800bb6f18b236d", + "version" : "10.19.2" + } + }, { "identity" : "dds-ios", "kind" : "remoteSourceControl", @@ -18,6 +36,15 @@ "version" : "0.2.17" } }, + { + "identity" : "firebase-ios-sdk", + "kind" : "remoteSourceControl", + "location" : "https://github.com/firebase/firebase-ios-sdk.git", + "state" : { + "revision" : "eca84fd638116dd6adb633b5a3f31cc7befcbb7d", + "version" : "10.29.0" + } + }, { "identity" : "flowkit", "kind" : "remoteSourceControl", @@ -27,6 +54,69 @@ "revision" : "9defc64f19529e053a0b74494e083839eaffef51" } }, + { + "identity" : "googleappmeasurement", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/GoogleAppMeasurement.git", + "state" : { + "revision" : "fe727587518729046fc1465625b9afd80b5ab361", + "version" : "10.28.0" + } + }, + { + "identity" : "googledatatransport", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/GoogleDataTransport.git", + "state" : { + "revision" : "a637d318ae7ae246b02d7305121275bc75ed5565", + "version" : "9.4.0" + } + }, + { + "identity" : "googleutilities", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/GoogleUtilities.git", + "state" : { + "revision" : "57a1d307f42df690fdef2637f3e5b776da02aad6", + "version" : "7.13.3" + } + }, + { + "identity" : "grpc-binary", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/grpc-binary.git", + "state" : { + "revision" : "e9fad491d0673bdda7063a0341fb6b47a30c5359", + "version" : "1.62.2" + } + }, + { + "identity" : "gtm-session-fetcher", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/gtm-session-fetcher.git", + "state" : { + "revision" : "a2ab612cb980066ee56d90d60d8462992c07f24b", + "version" : "3.5.0" + } + }, + { + "identity" : "interop-ios-for-google-sdks", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/interop-ios-for-google-sdks.git", + "state" : { + "revision" : "2d12673670417654f08f5f90fdd62926dc3a2648", + "version" : "100.0.0" + } + }, + { + "identity" : "leveldb", + "kind" : "remoteSourceControl", + "location" : "https://github.com/firebase/leveldb.git", + "state" : { + "revision" : "a0bc79961d7be727d258d33d5a6b2f1023270ba1", + "version" : "1.22.5" + } + }, { "identity" : "moya", "kind" : "remoteSourceControl", @@ -36,6 +126,24 @@ "version" : "15.0.3" } }, + { + "identity" : "nanopb", + "kind" : "remoteSourceControl", + "location" : "https://github.com/firebase/nanopb.git", + "state" : { + "revision" : "b7e1104502eca3a213b46303391ca4d3bc8ddec1", + "version" : "2.30910.0" + } + }, + { + "identity" : "promises", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/promises.git", + "state" : { + "revision" : "540318ecedd63d883069ae7f1ed811a2df00b6ac", + "version" : "2.4.0" + } + }, { "identity" : "reactiveswift", "kind" : "remoteSourceControl", @@ -63,6 +171,15 @@ "version" : "0.0.2" } }, + { + "identity" : "swift-protobuf", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-protobuf.git", + "state" : { + "revision" : "edb6ed4919f7756157fe02f2552b7e3850a538e5", + "version" : "1.28.1" + } + }, { "identity" : "swift-syntax", "kind" : "remoteSourceControl", diff --git a/Tuist/Package.swift b/Tuist/Package.swift index a2ba71e..62663fa 100644 --- a/Tuist/Package.swift +++ b/Tuist/Package.swift @@ -30,6 +30,7 @@ let package = Package( .package(url: "https://github.com/Mercen-Lee/FlowKit", branch: "main"), .package(url: "https://github.com/Mercen-Lee/SignKit", exact: "0.0.2"), .package(url: "https://github.com/lorenzofiamingo/swiftui-cached-async-image", exact: "2.1.1"), - .package(url: "https://github.com/bestswlkh0310/SwiftBok", exact: "1.2.0") + .package(url: "https://github.com/bestswlkh0310/SwiftBok", exact: "1.2.0"), + .package(url: "https://github.com/firebase/firebase-ios-sdk.git", from: "10.0.0") ] ) From 1f2e27c6bdf84c1eca0c56d362013108a870397e Mon Sep 17 00:00:00 2001 From: leeyoonchae Date: Mon, 30 Sep 2024 10:02:12 +0900 Subject: [PATCH 2/5] feat: add push message --- Projects/App/Project.swift | 1 - Projects/App/iOS/Source/AppDelegate.swift | 106 ++++++++++++++++++++++ Projects/App/iOS/Source/AppMain.swift | 2 + Tuist/Package.swift | 1 - 4 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 Projects/App/iOS/Source/AppDelegate.swift diff --git a/Projects/App/Project.swift b/Projects/App/Project.swift index fd00716..493fbbe 100644 --- a/Projects/App/Project.swift +++ b/Projects/App/Project.swift @@ -40,7 +40,6 @@ let project = Project( .project(target: "Repository", path: .relativeToRoot("Projects/Data")), .project(target: "DIContainer", path: .relativeToRoot("Projects/DIContainer")), .target(name: "DodamDodamWidget"), - .external(name: "FirebaseAnalytics"), .external(name: "FirebaseMessaging") ] ), diff --git a/Projects/App/iOS/Source/AppDelegate.swift b/Projects/App/iOS/Source/AppDelegate.swift new file mode 100644 index 0000000..2104e63 --- /dev/null +++ b/Projects/App/iOS/Source/AppDelegate.swift @@ -0,0 +1,106 @@ +// +// AppDelegate.swift +// DodamDodam +// +// Created by dgsw8th61 on 9/19/24. +// + +import SwiftUI +import Firebase +import FirebaseMessaging + +class AppDelegate: NSObject, UIApplicationDelegate{ + + let gcmMessageIDKey = "gcm.message_id" + + // 앱이 켜졌을 때 + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { + + // 파이어베이스 설정 + FirebaseApp.configure() + + // Setting Up Notifications... + // 원격 알림 등록 + if #available(iOS 10.0, *) { + // For iOS 10 display notification (sent via APNS) + UNUserNotificationCenter.current().delegate = self + + let authOption: UNAuthorizationOptions = [.alert, .badge, .sound] + UNUserNotificationCenter.current().requestAuthorization( + options: authOption, + completionHandler: {_, _ in }) + } else { + let settings: UIUserNotificationSettings = + UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) + application.registerUserNotificationSettings(settings) + } + + application.registerForRemoteNotifications() + + // Setting Up Cloud Messaging... + // 메세징 델리겟 + Messaging.messaging().delegate = self + UNUserNotificationCenter.current().delegate = self + return true + } + + // fcm 토큰이 등록 되었을 때 + func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { + Messaging.messaging().apnsToken = deviceToken + } + +} + +// Cloud Messaging... +extension AppDelegate: MessagingDelegate { + + // fcm 등록 토큰을 받았을 때 + func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { + + print("토큰을 받았다") + // Store this token to firebase and retrieve when to send message to someone... + let dataDict: [String: String] = ["token": fcmToken ?? ""] + + // Store token in Firestore For Sending Notifications From Server in Future... + print(dataDict) + + } +} + +// User Notifications...[AKA InApp Notification...] + +@available(iOS 10, *) +extension AppDelegate: UNUserNotificationCenterDelegate { + + // 푸시 메세지가 앱이 켜져있을 때 나올떄 + func userNotificationCenter(_ center: UNUserNotificationCenter, + willPresent notification: UNNotification, + withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) + -> Void) { + + let userInfo = notification.request.content.userInfo + + // Do Something With MSG Data... + if let messageID = userInfo[gcmMessageIDKey] { + print("Message ID: \(messageID)") + } + + print(userInfo) + + completionHandler([[.banner, .badge, .sound]]) + } + + // 푸시메세지를 받았을 떄 + func userNotificationCenter(_ center: UNUserNotificationCenter, + didReceive response: UNNotificationResponse, + withCompletionHandler completionHandler: @escaping () -> Void) { + let userInfo = response.notification.request.content.userInfo + + // Do Something With MSG Data... + if let messageID = userInfo[gcmMessageIDKey] { + print("Message ID: \(messageID)") + } + print(userInfo) + completionHandler() + } +} diff --git a/Projects/App/iOS/Source/AppMain.swift b/Projects/App/iOS/Source/AppMain.swift index 19dbc4a..a36908e 100644 --- a/Projects/App/iOS/Source/AppMain.swift +++ b/Projects/App/iOS/Source/AppMain.swift @@ -16,6 +16,8 @@ import FlowKit @main struct AppMain: App { + @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate + init() { Pretendard.register() DependencyProvider.shared.register() diff --git a/Tuist/Package.swift b/Tuist/Package.swift index 62663fa..66fcc10 100644 --- a/Tuist/Package.swift +++ b/Tuist/Package.swift @@ -30,7 +30,6 @@ let package = Package( .package(url: "https://github.com/Mercen-Lee/FlowKit", branch: "main"), .package(url: "https://github.com/Mercen-Lee/SignKit", exact: "0.0.2"), .package(url: "https://github.com/lorenzofiamingo/swiftui-cached-async-image", exact: "2.1.1"), - .package(url: "https://github.com/bestswlkh0310/SwiftBok", exact: "1.2.0"), .package(url: "https://github.com/firebase/firebase-ios-sdk.git", from: "10.0.0") ] ) From 9a7cd484b2ff22b948b97d1ec2133569cc76227e Mon Sep 17 00:00:00 2001 From: hhhello Date: Mon, 30 Sep 2024 17:47:17 +0900 Subject: [PATCH 3/5] chore: Fix fcm infra --- .gitignore | 2 + Projects/App/iOS/Source/AppDelegate.swift | 86 +++++++++++------------ Tuist/Package.resolved | 21 ------ 3 files changed, 43 insertions(+), 66 deletions(-) diff --git a/.gitignore b/.gitignore index 16c1cab..c85b3cb 100644 --- a/.gitignore +++ b/.gitignore @@ -144,3 +144,5 @@ Derived/ ### Tuist managed dependencies ### Tuist/Dependencies + +GoogleService-info.plist diff --git a/Projects/App/iOS/Source/AppDelegate.swift b/Projects/App/iOS/Source/AppDelegate.swift index 2104e63..4938da9 100644 --- a/Projects/App/iOS/Source/AppDelegate.swift +++ b/Projects/App/iOS/Source/AppDelegate.swift @@ -8,27 +8,24 @@ import SwiftUI import Firebase import FirebaseMessaging +import DIContainer +import Domain -class AppDelegate: NSObject, UIApplicationDelegate{ +class AppDelegate: NSObject, UIApplicationDelegate { let gcmMessageIDKey = "gcm.message_id" // 앱이 켜졌을 때 - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { // 파이어베이스 설정 FirebaseApp.configure() - + // Setting Up Notifications... // 원격 알림 등록 if #available(iOS 10.0, *) { // For iOS 10 display notification (sent via APNS) - UNUserNotificationCenter.current().delegate = self - - let authOption: UNAuthorizationOptions = [.alert, .badge, .sound] - UNUserNotificationCenter.current().requestAuthorization( - options: authOption, - completionHandler: {_, _ in }) + UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { _, _ in } } else { let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) @@ -41,6 +38,7 @@ class AppDelegate: NSObject, UIApplicationDelegate{ // 메세징 델리겟 Messaging.messaging().delegate = self UNUserNotificationCenter.current().delegate = self + UIApplication.shared.registerForRemoteNotifications() return true } @@ -48,7 +46,6 @@ class AppDelegate: NSObject, UIApplicationDelegate{ func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { Messaging.messaging().apnsToken = deviceToken } - } // Cloud Messaging... @@ -56,14 +53,11 @@ extension AppDelegate: MessagingDelegate { // fcm 등록 토큰을 받았을 때 func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { - - print("토큰을 받았다") - // Store this token to firebase and retrieve when to send message to someone... - let dataDict: [String: String] = ["token": fcmToken ?? ""] + guard let fcmToken else { + print("❌ AppDelegate.messaging.didReceiveRegistrationToken - FCM token is nil") + return + } - // Store token in Firestore For Sending Notifications From Server in Future... - print(dataDict) - } } @@ -71,36 +65,38 @@ extension AppDelegate: MessagingDelegate { @available(iOS 10, *) extension AppDelegate: UNUserNotificationCenterDelegate { - - // 푸시 메세지가 앱이 켜져있을 때 나올떄 - func userNotificationCenter(_ center: UNUserNotificationCenter, - willPresent notification: UNNotification, - withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) - -> Void) { - - let userInfo = notification.request.content.userInfo - - // Do Something With MSG Data... - if let messageID = userInfo[gcmMessageIDKey] { - print("Message ID: \(messageID)") + + // 푸시 메세지가 앱이 켜져 있을 때 나올 때 + func userNotificationCenter( + _ center: UNUserNotificationCenter, + willPresent notification: UNNotification + ) async -> UNNotificationPresentationOptions { + let userInfo = notification.request.content.userInfo + + // Do Something With MSG Data... + if let messageID = userInfo[gcmMessageIDKey] { + print("✅ AppDelegate.userNotificationCenter.didReceive - Message ID: \(messageID)") + } + print("✅ AppDelegate.userNotificationCenter.didReceive - \(userInfo)") + + return if #available(iOS 14.0, *) { + [[.list, .banner, .sound]] + } else { + [[.alert, .sound]] + } } - print(userInfo) - - completionHandler([[.banner, .badge, .sound]]) - } - // 푸시메세지를 받았을 떄 - func userNotificationCenter(_ center: UNUserNotificationCenter, - didReceive response: UNNotificationResponse, - withCompletionHandler completionHandler: @escaping () -> Void) { - let userInfo = response.notification.request.content.userInfo - - // Do Something With MSG Data... - if let messageID = userInfo[gcmMessageIDKey] { - print("Message ID: \(messageID)") + func userNotificationCenter( + _ center: UNUserNotificationCenter, + didReceive response: UNNotificationResponse + ) async { + let userInfo = response.notification.request.content.userInfo + + // Do Something With MSG Data... + if let messageID = userInfo[gcmMessageIDKey] { + print("✅ AppDelegate.userNotificationCenter.didReceive - Message ID: \(messageID)") + } + print("✅ AppDelegate.userNotificationCenter.didReceive - \(response)") } - print(userInfo) - completionHandler() - } } diff --git a/Tuist/Package.resolved b/Tuist/Package.resolved index bf9574c..1b623ae 100644 --- a/Tuist/Package.resolved +++ b/Tuist/Package.resolved @@ -190,7 +190,6 @@ } }, { -<<<<<<< HEAD "identity" : "swift-protobuf", "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-protobuf.git", @@ -200,26 +199,6 @@ } }, { - "identity" : "swift-syntax", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-syntax.git", - "state" : { - "revision" : "64889f0c732f210a935a0ad7cda38f77f876262d", - "version" : "509.1.1" - } - }, - { - "identity" : "swiftbok", - "kind" : "remoteSourceControl", - "location" : "https://github.com/bestswlkh0310/SwiftBok", - "state" : { - "revision" : "266261801504e6f915e860de42166915460ca604", - "version" : "1.2.0" - } - }, - { -======= ->>>>>>> origin/develop "identity" : "swiftui-cached-async-image", "kind" : "remoteSourceControl", "location" : "https://github.com/lorenzofiamingo/swiftui-cached-async-image", From c6921479111f0c3331b36af8769052c783896582 Mon Sep 17 00:00:00 2001 From: hhhello Date: Mon, 30 Sep 2024 18:24:00 +0900 Subject: [PATCH 4/5] feat: Send pushToken to login --- Projects/App/Project.swift | 7 ++++--- Projects/App/iOS/Source/AppDelegate.swift | 5 +++-- .../Data/Network/Source/Remote/RemoteInterceptor.swift | 5 +++-- Projects/Data/Project.swift | 1 + Projects/Domain/Source/Request/Auth/PostLoginRequest.swift | 4 +++- Projects/Feature/Project.swift | 3 ++- Projects/Feature/Source/All/AllView.swift | 1 - Projects/Feature/Source/Auth/Login/LoginViewModel.swift | 4 +++- 8 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Projects/App/Project.swift b/Projects/App/Project.swift index dc633f2..d1c5117 100644 --- a/Projects/App/Project.swift +++ b/Projects/App/Project.swift @@ -30,18 +30,19 @@ let project = Project( "CFBundleVersion": "1", "UISupportedInterfaceOrientations": ["UIInterfaceOrientationPortrait"], "UIMainStoryboardFile": "", - "UILaunchStoryboardName": "LaunchScreen" + "UILaunchStoryboardName": "LaunchScreen", + "FirebaseAppDelegateProxyEnabled": .boolean(false) ] ), sources: ["iOS/Source/**"], resources: ["iOS/Resource/**"], +// entitlements: .file(path: "iOS/Resource/DodamDodam.entitlements"), scripts: [.swiftLint], dependencies: [ .project(target: "Feature", path: .relativeToRoot("Projects/Feature")), .project(target: "Repository", path: .relativeToRoot("Projects/Data")), .project(target: "DIContainer", path: .relativeToRoot("Projects/DIContainer")), - .target(name: "DodamDodamWidget"), - .external(name: "FirebaseMessaging") + .target(name: "DodamDodamWidget") ] ), .target( diff --git a/Projects/App/iOS/Source/AppDelegate.swift b/Projects/App/iOS/Source/AppDelegate.swift index 4938da9..c8a3eaa 100644 --- a/Projects/App/iOS/Source/AppDelegate.swift +++ b/Projects/App/iOS/Source/AppDelegate.swift @@ -44,6 +44,7 @@ class AppDelegate: NSObject, UIApplicationDelegate { // fcm 토큰이 등록 되었을 때 func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { + print("✅ AppDelegate.application.didRegisterForRemoteNotificationsWithDeviceToken - apnsToken \(deviceToken)") Messaging.messaging().apnsToken = deviceToken } } @@ -51,13 +52,13 @@ class AppDelegate: NSObject, UIApplicationDelegate { // Cloud Messaging... extension AppDelegate: MessagingDelegate { - // fcm 등록 토큰을 받았을 때 + // fcm 등록 토큰이 갱신되었을 때 func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { guard let fcmToken else { print("❌ AppDelegate.messaging.didReceiveRegistrationToken - FCM token is nil") return } - + print("✅ AppDelegate.Fmessaging.didReceiveRegistrationToken - fcmToken \(fcmToken)") } } diff --git a/Projects/Data/Network/Source/Remote/RemoteInterceptor.swift b/Projects/Data/Network/Source/Remote/RemoteInterceptor.swift index 59f1ecf..88cd937 100644 --- a/Projects/Data/Network/Source/Remote/RemoteInterceptor.swift +++ b/Projects/Data/Network/Source/Remote/RemoteInterceptor.swift @@ -10,6 +10,7 @@ import Alamofire import SignKit import Domain import DIContainer +import FirebaseMessaging class RemoteInterceptor: RequestInterceptor { @@ -73,11 +74,11 @@ class RemoteInterceptor: RequestInterceptor { if let id = Sign.id, let pw = Sign.password { do { + let pushToken = try await Messaging.messaging().token() _ = try await authRepository.postLogin( - .init(id: id, pw: pw) + .init(id: id, pw: pw, pushToken: pushToken) ) DispatchQueue.main.async { -// self.retryCount += 1 completion(.retry) } } catch let error { diff --git a/Projects/Data/Project.swift b/Projects/Data/Project.swift index 738ca35..a896fee 100644 --- a/Projects/Data/Project.swift +++ b/Projects/Data/Project.swift @@ -43,6 +43,7 @@ let project = Project( .project(target: "Domain", path: .relativeToRoot("Projects/Domain")), .external(name: "Moya"), .external(name: "SignKit"), + .external(name: "FirebaseMessaging"), .project(target: "Shared", path: .relativeToRoot("Projects/Shared")) ] ), diff --git a/Projects/Domain/Source/Request/Auth/PostLoginRequest.swift b/Projects/Domain/Source/Request/Auth/PostLoginRequest.swift index 7d984a1..9080778 100644 --- a/Projects/Domain/Source/Request/Auth/PostLoginRequest.swift +++ b/Projects/Domain/Source/Request/Auth/PostLoginRequest.swift @@ -9,9 +9,11 @@ public struct PostLoginRequest: RequestProtocol { public let id: String public let pw: String + public let pushToken: String - public init(id: String, pw: String) { + public init(id: String, pw: String, pushToken: String) { self.id = id self.pw = pw + self.pushToken = pushToken } } diff --git a/Projects/Feature/Project.swift b/Projects/Feature/Project.swift index c464958..0ca470c 100644 --- a/Projects/Feature/Project.swift +++ b/Projects/Feature/Project.swift @@ -17,7 +17,8 @@ let project = Project( .project(target: "DIContainer", path: .relativeToRoot("Projects/DIContainer")), .external(name: "CachedAsyncImage"), .external(name: "SwiftUIIntrospect"), - .project(target: "Shared", path: .relativeToRoot("Projects/Shared")) + .project(target: "Shared", path: .relativeToRoot("Projects/Shared")), + .external(name: "FirebaseMessaging") ] ) ] diff --git a/Projects/Feature/Source/All/AllView.swift b/Projects/Feature/Source/All/AllView.swift index 5bc52f3..f15b215 100644 --- a/Projects/Feature/Source/All/AllView.swift +++ b/Projects/Feature/Source/All/AllView.swift @@ -64,7 +64,6 @@ struct AllView: View { .padding(.bottom, 8) } else { Button { - dump(flow) flow.push(LoginView()) } label: { HStack(spacing: 16) { diff --git a/Projects/Feature/Source/Auth/Login/LoginViewModel.swift b/Projects/Feature/Source/Auth/Login/LoginViewModel.swift index fac4e79..91f1a20 100644 --- a/Projects/Feature/Source/Auth/Login/LoginViewModel.swift +++ b/Projects/Feature/Source/Auth/Login/LoginViewModel.swift @@ -9,6 +9,7 @@ import Combine import SignKit import DIContainer import Domain +import FirebaseMessaging class LoginViewModel: ObservableObject { @@ -28,8 +29,9 @@ class LoginViewModel: ObservableObject { func postLogin(_ completion: @escaping () -> Void) async { isShowingAlert = false do { + let pushToken = try await Messaging.messaging().token() _ = try await authRepository.postLogin( - .init(id: idText, pw: pwText) + .init(id: idText, pw: pwText, pushToken: pushToken) ) completion() } catch let error { From 2db712ae3713513aa32aa9a0ba5cb0ba54c245f9 Mon Sep 17 00:00:00 2001 From: hhhello Date: Tue, 29 Oct 2024 12:13:04 +0900 Subject: [PATCH 5/5] fix: To save pushToken --- .gitignore | 2 +- Projects/App/Project.swift | 9 +++++++-- Projects/App/{ => iOS/Resource}/DodamDodam.entitlements | 0 Projects/App/iOS/Source/AppDelegate.swift | 4 +++- .../Data/Network/Source/Remote/RemoteInterceptor.swift | 6 ++++-- Projects/Data/Project.swift | 1 - Projects/Feature/Project.swift | 3 +-- Projects/Feature/Source/Auth/Login/LoginViewModel.swift | 8 ++++++-- 8 files changed, 22 insertions(+), 11 deletions(-) rename Projects/App/{ => iOS/Resource}/DodamDodam.entitlements (100%) diff --git a/.gitignore b/.gitignore index c85b3cb..1fb46d8 100644 --- a/.gitignore +++ b/.gitignore @@ -145,4 +145,4 @@ Derived/ ### Tuist managed dependencies ### Tuist/Dependencies -GoogleService-info.plist +GoogleService-Info.plist diff --git a/Projects/App/Project.swift b/Projects/App/Project.swift index d1c5117..92accf5 100644 --- a/Projects/App/Project.swift +++ b/Projects/App/Project.swift @@ -31,17 +31,22 @@ let project = Project( "UISupportedInterfaceOrientations": ["UIInterfaceOrientationPortrait"], "UIMainStoryboardFile": "", "UILaunchStoryboardName": "LaunchScreen", - "FirebaseAppDelegateProxyEnabled": .boolean(false) + "FirebaseAppDelegateProxyEnabled": .boolean(false), + "UIBackgroundModes": [ + "remote-notification", + "fetch" + ] ] ), sources: ["iOS/Source/**"], resources: ["iOS/Resource/**"], -// entitlements: .file(path: "iOS/Resource/DodamDodam.entitlements"), + entitlements: .file(path: "iOS/Resource/DodamDodam.entitlements"), scripts: [.swiftLint], dependencies: [ .project(target: "Feature", path: .relativeToRoot("Projects/Feature")), .project(target: "Repository", path: .relativeToRoot("Projects/Data")), .project(target: "DIContainer", path: .relativeToRoot("Projects/DIContainer")), + .external(name: "FirebaseMessaging"), .target(name: "DodamDodamWidget") ] ), diff --git a/Projects/App/DodamDodam.entitlements b/Projects/App/iOS/Resource/DodamDodam.entitlements similarity index 100% rename from Projects/App/DodamDodam.entitlements rename to Projects/App/iOS/Resource/DodamDodam.entitlements diff --git a/Projects/App/iOS/Source/AppDelegate.swift b/Projects/App/iOS/Source/AppDelegate.swift index c8a3eaa..95ef4ee 100644 --- a/Projects/App/iOS/Source/AppDelegate.swift +++ b/Projects/App/iOS/Source/AppDelegate.swift @@ -58,7 +58,9 @@ extension AppDelegate: MessagingDelegate { print("❌ AppDelegate.messaging.didReceiveRegistrationToken - FCM token is nil") return } - print("✅ AppDelegate.Fmessaging.didReceiveRegistrationToken - fcmToken \(fcmToken)") + + print("✅ AppDelegate.messaging.didReceiveRegistrationToken - fcmToken \(fcmToken)") + UserDefaults.standard.setValue(fcmToken, forKey: "pushToken") } } diff --git a/Projects/Data/Network/Source/Remote/RemoteInterceptor.swift b/Projects/Data/Network/Source/Remote/RemoteInterceptor.swift index 88cd937..08a1247 100644 --- a/Projects/Data/Network/Source/Remote/RemoteInterceptor.swift +++ b/Projects/Data/Network/Source/Remote/RemoteInterceptor.swift @@ -10,7 +10,6 @@ import Alamofire import SignKit import Domain import DIContainer -import FirebaseMessaging class RemoteInterceptor: RequestInterceptor { @@ -74,7 +73,10 @@ class RemoteInterceptor: RequestInterceptor { if let id = Sign.id, let pw = Sign.password { do { - let pushToken = try await Messaging.messaging().token() + guard let pushToken = UserDefaults.standard.string(forKey: "pushToken") else { + completion(.doNotRetryWithError(error)) + return + } _ = try await authRepository.postLogin( .init(id: id, pw: pw, pushToken: pushToken) ) diff --git a/Projects/Data/Project.swift b/Projects/Data/Project.swift index a896fee..738ca35 100644 --- a/Projects/Data/Project.swift +++ b/Projects/Data/Project.swift @@ -43,7 +43,6 @@ let project = Project( .project(target: "Domain", path: .relativeToRoot("Projects/Domain")), .external(name: "Moya"), .external(name: "SignKit"), - .external(name: "FirebaseMessaging"), .project(target: "Shared", path: .relativeToRoot("Projects/Shared")) ] ), diff --git a/Projects/Feature/Project.swift b/Projects/Feature/Project.swift index 0ca470c..c464958 100644 --- a/Projects/Feature/Project.swift +++ b/Projects/Feature/Project.swift @@ -17,8 +17,7 @@ let project = Project( .project(target: "DIContainer", path: .relativeToRoot("Projects/DIContainer")), .external(name: "CachedAsyncImage"), .external(name: "SwiftUIIntrospect"), - .project(target: "Shared", path: .relativeToRoot("Projects/Shared")), - .external(name: "FirebaseMessaging") + .project(target: "Shared", path: .relativeToRoot("Projects/Shared")) ] ) ] diff --git a/Projects/Feature/Source/Auth/Login/LoginViewModel.swift b/Projects/Feature/Source/Auth/Login/LoginViewModel.swift index 91f1a20..ebd7cd9 100644 --- a/Projects/Feature/Source/Auth/Login/LoginViewModel.swift +++ b/Projects/Feature/Source/Auth/Login/LoginViewModel.swift @@ -6,10 +6,10 @@ // import Combine +import Foundation import SignKit import DIContainer import Domain -import FirebaseMessaging class LoginViewModel: ObservableObject { @@ -29,7 +29,11 @@ class LoginViewModel: ObservableObject { func postLogin(_ completion: @escaping () -> Void) async { isShowingAlert = false do { - let pushToken = try await Messaging.messaging().token() + guard let pushToken = UserDefaults.standard.string(forKey: "pushToken") else { + print("pushToken is nil") + isShowingAlert = true + return + } _ = try await authRepository.postLogin( .init(id: idText, pw: pwText, pushToken: pushToken) )