From 2d24cb42508cc7a8fdfd18e21fd7791de29a5e88 Mon Sep 17 00:00:00 2001 From: hooni Date: Wed, 17 Jul 2024 01:52:47 +0900 Subject: [PATCH] =?UTF-8?q?feat/#159=20-=20FCM=20=ED=86=A0=ED=81=B0=20?= =?UTF-8?q?=EA=B0=80=EC=A0=B8=EC=98=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KkuMulKum.xcodeproj/project.pbxproj | 8 +++ .../xcshareddata/swiftpm/Package.resolved | 2 +- KkuMulKum/Application/AppDelegate.swift | 62 ++++++++++++++++++- KkuMulKum/KkuMulKum.entitlements | 2 + KkuMulKum/Resource/GoogleService-Info.plist | 30 +++++++++ KkuMulKum/Resource/Info.plist | 2 + 6 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 KkuMulKum/Resource/GoogleService-Info.plist diff --git a/KkuMulKum.xcodeproj/project.pbxproj b/KkuMulKum.xcodeproj/project.pbxproj index 31b47e41..a255cf32 100644 --- a/KkuMulKum.xcodeproj/project.pbxproj +++ b/KkuMulKum.xcodeproj/project.pbxproj @@ -48,6 +48,7 @@ 789873342C3D1A7B00435E96 /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789873312C3D1A7B00435E96 /* LoginView.swift */; }; 789AD4B32C3C0093002E2688 /* SocialLoginResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789AD4B22C3C0093002E2688 /* SocialLoginResponseModel.swift */; }; 789AD4B52C3C0147002E2688 /* ResissueResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789AD4B42C3C0147002E2688 /* ResissueResponseModel.swift */; }; + 789D73AF2C46D99B00C7077D /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 789D73AE2C46D99B00C7077D /* GoogleService-Info.plist */; }; 78B9286C2C29402C006D9942 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B9286B2C29402C006D9942 /* AppDelegate.swift */; }; 78B9286E2C29402C006D9942 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B9286D2C29402C006D9942 /* SceneDelegate.swift */; }; 78B928752C29402E006D9942 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 78B928742C29402E006D9942 /* Assets.xcassets */; }; @@ -131,6 +132,8 @@ 789873312C3D1A7B00435E96 /* LoginView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = ""; }; 789AD4B22C3C0093002E2688 /* SocialLoginResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocialLoginResponseModel.swift; sourceTree = ""; }; 789AD4B42C3C0147002E2688 /* ResissueResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResissueResponseModel.swift; sourceTree = ""; }; + 789D73AE2C46D99B00C7077D /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; + 789D73B02C46DACD00C7077D /* KkuMulKum.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = KkuMulKum.entitlements; sourceTree = ""; }; 78B928682C29402C006D9942 /* KkuMulKum.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KkuMulKum.app; sourceTree = BUILT_PRODUCTS_DIR; }; 78B9286B2C29402C006D9942 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 78B9286D2C29402C006D9942 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -298,6 +301,7 @@ 78B9286A2C29402C006D9942 /* KkuMulKum */ = { isa = PBXGroup; children = ( + 789D73B02C46DACD00C7077D /* KkuMulKum.entitlements */, DE254AA12C31106700A4015E /* Application */, DE254AA22C31107700A4015E /* Source */, DE254AA32C31107C00A4015E /* Resource */, @@ -444,6 +448,7 @@ 78B928742C29402E006D9942 /* Assets.xcassets */, 78B928762C29402E006D9942 /* LaunchScreen.storyboard */, 785AE1D02C3B07A600677CA0 /* PrivacyInfo.plist */, + 789D73AE2C46D99B00C7077D /* GoogleService-Info.plist */, 78B928792C29402E006D9942 /* Info.plist */, DE9E187E2C3BA49B00DB76B4 /* Component */, DE8247FE2C36E846000601BC /* ObservablePattern */, @@ -757,6 +762,7 @@ DE254AC52C311DC200A4015E /* Pretendard-Regular.otf in Resources */, DE254AC92C311DC200A4015E /* Pretendard-SemiBold.otf in Resources */, DE254AC42C311DC200A4015E /* Pretendard-ExtraBold.otf in Resources */, + 789D73AF2C46D99B00C7077D /* GoogleService-Info.plist in Resources */, DE254AA52C31131600A4015E /* Color.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -973,6 +979,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = KkuMulKum/KkuMulKum.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Manual; @@ -1006,6 +1013,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = KkuMulKum/KkuMulKum.entitlements; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 1; diff --git a/KkuMulKum.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/KkuMulKum.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 45b79d88..e75f1a77 100644 --- a/KkuMulKum.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/KkuMulKum.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -174,7 +174,7 @@ { "identity" : "rxswift", "kind" : "remoteSourceControl", - "location" : "https://github.com/ReactiveX/RxSwift.git", + "location" : "https://github.com/ReactiveX/RxSwift", "state" : { "revision" : "b06a8c8596e4c3e8e7788e08e720e3248563ce6a", "version" : "6.7.1" diff --git a/KkuMulKum/Application/AppDelegate.swift b/KkuMulKum/Application/AppDelegate.swift index 00e72fe0..b8479bd9 100644 --- a/KkuMulKum/Application/AppDelegate.swift +++ b/KkuMulKum/Application/AppDelegate.swift @@ -9,14 +9,17 @@ import UIKit import KakaoSDKCommon import KakaoSDKAuth +import Firebase +import FirebaseMessaging @main class AppDelegate: UIResponder, UIApplicationDelegate { + func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { - // KakaoSDK 초기화 과정에서 앱 키를 동적으로 불러오기 + // KakaoSDK 초기화 if let kakaoAppKey = fetchKakaoAppKeyFromPrivacyInfo() { KakaoSDK.initSDK(appKey: kakaoAppKey) print("Kakao SDK initialized with app key: \(kakaoAppKey)") @@ -24,6 +27,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate { print("Failed to load KAKAO_APP_KEY from PrivacyInfo.plist") } + // Firebase 초기화 및 FCM 설정 + setupFirebase(application: application) + return true } @@ -62,3 +68,57 @@ class AppDelegate: UIResponder, UIApplicationDelegate { didDiscardSceneSessions sceneSessions: Set ) {} } + +// MARK: - Firebase Setup + +extension AppDelegate: MessagingDelegate, UNUserNotificationCenterDelegate { + + func setupFirebase(application: UIApplication) { + FirebaseApp.configure() + FirebaseConfiguration.shared.setLoggerLevel(.min) + Analytics.logEvent(AnalyticsEventAppOpen, parameters: nil) + + Messaging.messaging().delegate = self + UNUserNotificationCenter.current().delegate = self + + let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] + UNUserNotificationCenter.current().requestAuthorization( + options: authOptions, + completionHandler: { _, _ in } + ) + + application.registerForRemoteNotifications() + + // FCM 토큰 가져오기 + Messaging.messaging().token { token, error in + if let error = error { + print("Error fetching FCM registration token: \(error)") + } else if let token = token { + print("FCM Token: \(token)") + UserDefaults.standard.set(token, forKey: "FCMToken") + } + } + } + + func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { + print("Firebase registration token: \(String(describing: fcmToken))") + + if let token = fcmToken { + UserDefaults.standard.set(token, forKey: "FCMToken") + } + } + + func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { + Messaging.messaging().apnsToken = deviceToken + + // APNS 토큰이 설정된 후 FCM 토큰 요청 + Messaging.messaging().token { token, error in + if let error = error { + print("Error fetching FCM registration token: \(error)") + } else if let token = token { + print("FCM Token: \(token)") + UserDefaults.standard.set(token, forKey: "FCMToken") + } + } + } +} diff --git a/KkuMulKum/KkuMulKum.entitlements b/KkuMulKum/KkuMulKum.entitlements index a812db50..80b5221d 100644 --- a/KkuMulKum/KkuMulKum.entitlements +++ b/KkuMulKum/KkuMulKum.entitlements @@ -2,6 +2,8 @@ + aps-environment + development com.apple.developer.applesignin Default diff --git a/KkuMulKum/Resource/GoogleService-Info.plist b/KkuMulKum/Resource/GoogleService-Info.plist new file mode 100644 index 00000000..6d1fc556 --- /dev/null +++ b/KkuMulKum/Resource/GoogleService-Info.plist @@ -0,0 +1,30 @@ + + + + + API_KEY + AIzaSyDnUv_WWDQH8uvv6BwwFH83AG2jR--3Rdw + GCM_SENDER_ID + 460232609196 + PLIST_VERSION + 1 + BUNDLE_ID + KkuMulKum.yizihn + PROJECT_ID + kkumulkum + STORAGE_BUCKET + kkumulkum.appspot.com + IS_ADS_ENABLED + + IS_ANALYTICS_ENABLED + + IS_APPINVITE_ENABLED + + IS_GCM_ENABLED + + IS_SIGNIN_ENABLED + + GOOGLE_APP_ID + 1:460232609196:ios:d1713e225bb9b39e26be09 + + \ No newline at end of file diff --git a/KkuMulKum/Resource/Info.plist b/KkuMulKum/Resource/Info.plist index baa28139..ba9b78a2 100644 --- a/KkuMulKum/Resource/Info.plist +++ b/KkuMulKum/Resource/Info.plist @@ -2,6 +2,8 @@ + FirebaseAppDelegateProxyEnabled + No UIUserInterfaceStyle Light CFBundleURLTypes