diff --git a/KkuMulKum.xcodeproj/project.pbxproj b/KkuMulKum.xcodeproj/project.pbxproj index d0c34198..2a50094e 100644 --- a/KkuMulKum.xcodeproj/project.pbxproj +++ b/KkuMulKum.xcodeproj/project.pbxproj @@ -52,6 +52,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 */; }; 789D73A72C46AF4900C7077D /* KeychainService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789D73A62C46AF4900C7077D /* KeychainService.swift */; }; 789D73A92C46BBB000C7077D /* PagePromiseSegmentedControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789D73A82C46BBB000C7077D /* PagePromiseSegmentedControl.swift */; }; 789D73AB2C46BEFF00C7077D /* ProfileTargetType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789D73AA2C46BEFF00C7077D /* ProfileTargetType.swift */; }; @@ -207,11 +208,12 @@ 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 = ""; }; 789D73A62C46AF4900C7077D /* KeychainService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainService.swift; sourceTree = ""; }; 789D73A82C46BBB000C7077D /* PagePromiseSegmentedControl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PagePromiseSegmentedControl.swift; sourceTree = ""; }; 789D73AA2C46BEFF00C7077D /* ProfileTargetType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileTargetType.swift; sourceTree = ""; }; 789D73AC2C46C19500C7077D /* ProfileModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileModel.swift; sourceTree = ""; }; - 78AED1312C3D94F2000AD80A /* KkuMulKum.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = KkuMulKum.entitlements; sourceTree = ""; }; 78AED1332C3D951F000AD80A /* NicknameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NicknameViewController.swift; sourceTree = ""; }; 78AED1362C3D98D1000AD80A /* NicknameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NicknameView.swift; sourceTree = ""; }; 78B928682C29402C006D9942 /* KkuMulKum.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KkuMulKum.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -511,7 +513,7 @@ 78B9286A2C29402C006D9942 /* KkuMulKum */ = { isa = PBXGroup; children = ( - 78AED1312C3D94F2000AD80A /* KkuMulKum.entitlements */, + 789D73B02C46DACD00C7077D /* KkuMulKum.entitlements */, DE254AA12C31106700A4015E /* Application */, DE254AA22C31107700A4015E /* Source */, DE254AA32C31107C00A4015E /* Resource */, @@ -1105,6 +1107,7 @@ 78B928742C29402E006D9942 /* Assets.xcassets */, 78B928762C29402E006D9942 /* LaunchScreen.storyboard */, 785AE1D02C3B07A600677CA0 /* PrivacyInfo.plist */, + 789D73AE2C46D99B00C7077D /* GoogleService-Info.plist */, 78B928792C29402E006D9942 /* Info.plist */, DE9E187E2C3BA49B00DB76B4 /* Component */, DE8247FE2C36E846000601BC /* ObservablePattern */, @@ -1473,6 +1476,8 @@ 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; }; diff --git a/KkuMulKum/Application/AppDelegate.swift b/KkuMulKum/Application/AppDelegate.swift index e4c9b001..24d74838 100644 --- a/KkuMulKum/Application/AppDelegate.swift +++ b/KkuMulKum/Application/AppDelegate.swift @@ -9,14 +9,16 @@ 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 { - sleep(1) //런치스크린 작동용 // KakaoSDK 초기화 과정에서 앱 키를 동적으로 불러오기 if let kakaoAppKey = fetchKakaoAppKeyFromPrivacyInfo() { @@ -26,6 +28,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { print("Failed to load KAKAO_APP_KEY from PrivacyInfo.plist") } + setupFirebase(application: application) return true } @@ -69,3 +72,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 0ccc911f..35bcabd2 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 2ed41a5a..aa26eb10 100644 --- a/KkuMulKum/Resource/Info.plist +++ b/KkuMulKum/Resource/Info.plist @@ -2,6 +2,8 @@ + FirebaseAppDelegateProxyEnabled + No LSApplicationQueriesSchemes kakaotalk