Skip to content

Commit

Permalink
Merge pull request #194 from OMZigak/feat/#159-fcmMake
Browse files Browse the repository at this point in the history
[feat] FCM 토큰 받아오기 추가
  • Loading branch information
hooni0918 committed Jul 16, 2024
2 parents ebacf86 + 4c0b9e9 commit 2993039
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 3 deletions.
9 changes: 7 additions & 2 deletions KkuMulKum.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -207,11 +208,12 @@
789873312C3D1A7B00435E96 /* LoginView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = "<group>"; };
789AD4B22C3C0093002E2688 /* SocialLoginResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocialLoginResponseModel.swift; sourceTree = "<group>"; };
789AD4B42C3C0147002E2688 /* ResissueResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResissueResponseModel.swift; sourceTree = "<group>"; };
789D73AE2C46D99B00C7077D /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
789D73B02C46DACD00C7077D /* KkuMulKum.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = KkuMulKum.entitlements; sourceTree = "<group>"; };
789D73A62C46AF4900C7077D /* KeychainService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainService.swift; sourceTree = "<group>"; };
789D73A82C46BBB000C7077D /* PagePromiseSegmentedControl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PagePromiseSegmentedControl.swift; sourceTree = "<group>"; };
789D73AA2C46BEFF00C7077D /* ProfileTargetType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileTargetType.swift; sourceTree = "<group>"; };
789D73AC2C46C19500C7077D /* ProfileModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileModel.swift; sourceTree = "<group>"; };
78AED1312C3D94F2000AD80A /* KkuMulKum.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = KkuMulKum.entitlements; sourceTree = "<group>"; };
78AED1332C3D951F000AD80A /* NicknameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NicknameViewController.swift; sourceTree = "<group>"; };
78AED1362C3D98D1000AD80A /* NicknameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NicknameView.swift; sourceTree = "<group>"; };
78B928682C29402C006D9942 /* KkuMulKum.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KkuMulKum.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -511,7 +513,7 @@
78B9286A2C29402C006D9942 /* KkuMulKum */ = {
isa = PBXGroup;
children = (
78AED1312C3D94F2000AD80A /* KkuMulKum.entitlements */,
789D73B02C46DACD00C7077D /* KkuMulKum.entitlements */,
DE254AA12C31106700A4015E /* Application */,
DE254AA22C31107700A4015E /* Source */,
DE254AA32C31107C00A4015E /* Resource */,
Expand Down Expand Up @@ -1105,6 +1107,7 @@
78B928742C29402E006D9942 /* Assets.xcassets */,
78B928762C29402E006D9942 /* LaunchScreen.storyboard */,
785AE1D02C3B07A600677CA0 /* PrivacyInfo.plist */,
789D73AE2C46D99B00C7077D /* GoogleService-Info.plist */,
78B928792C29402E006D9942 /* Info.plist */,
DE9E187E2C3BA49B00DB76B4 /* Component */,
DE8247FE2C36E846000601BC /* ObservablePattern */,
Expand Down Expand Up @@ -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;
};
Expand Down
59 changes: 58 additions & 1 deletion KkuMulKum/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -26,6 +28,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
print("Failed to load KAKAO_APP_KEY from PrivacyInfo.plist")
}

setupFirebase(application: application)

return true
}
Expand Down Expand Up @@ -69,3 +72,57 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
didDiscardSceneSessions sceneSessions: Set<UISceneSession>
) {}
}

// 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")
}
}
}
}
2 changes: 2 additions & 0 deletions KkuMulKum/KkuMulKum.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.developer.applesignin</key>
<array>
<string>Default</string>
Expand Down
30 changes: 30 additions & 0 deletions KkuMulKum/Resource/GoogleService-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>API_KEY</key>
<string>AIzaSyDnUv_WWDQH8uvv6BwwFH83AG2jR--3Rdw</string>
<key>GCM_SENDER_ID</key>
<string>460232609196</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>KkuMulKum.yizihn</string>
<key>PROJECT_ID</key>
<string>kkumulkum</string>
<key>STORAGE_BUCKET</key>
<string>kkumulkum.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
<false></false>
<key>IS_APPINVITE_ENABLED</key>
<true></true>
<key>IS_GCM_ENABLED</key>
<true></true>
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:460232609196:ios:d1713e225bb9b39e26be09</string>
</dict>
</plist>
2 changes: 2 additions & 0 deletions KkuMulKum/Resource/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>FirebaseAppDelegateProxyEnabled</key>
<string>No</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>kakaotalk</string>
Expand Down

0 comments on commit 2993039

Please sign in to comment.