Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/#350 카카오로그인 구현완료 #351

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions KkuMulKum.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1213,13 +1213,6 @@
path = Tardy;
sourceTree = "<group>";
};
DD9F59642C7C7E3B00E928DF /* Recovered References */ = {
isa = PBXGroup;
children = (
);
name = "Recovered References";
sourceTree = "<group>";
};
DD9F59652C7C7E5C00E928DF /* Cell */ = {
isa = PBXGroup;
children = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Release"
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
Expand All @@ -49,6 +49,13 @@
ReferencedContainer = "container:KkuMulKum.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<EnvironmentVariables>
<EnvironmentVariable
key = "IDEPreferLogStreaming"
value = "YES"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
25 changes: 8 additions & 17 deletions KkuMulKum/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import UIKit

import KakaoSDKCommon
import KakaoSDKAuth
import Firebase
Expand All @@ -19,30 +20,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {

UNUserNotificationCenter.current().delegate = LocalNotificationManager.shared

// KakaoSDK 초기화 과정에서 앱 키를 동적으로 불러오기
if let kakaoAppKey = fetchKakaoAppKeyFromPrivacyInfo() {
KakaoSDK.initSDK(appKey: kakaoAppKey)
// KakaoSDK 초기화
if let kakaoAppKey = Bundle.main.privacyInfo?["NATIVE_APP_KEY"] as? String {
KakaoSDK.initSDK(appKey: kakaoAppKey, loggingEnable: true)
print("Kakao SDK initialized with app key: \(kakaoAppKey)")
Comment on lines +25 to 26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

성공했을 때는 print 디버깅은 필요없을 것 같네요.

} else {
print("Failed to load KAKAO_APP_KEY from PrivacyInfo.plist")
}

setupFirebase(application: application)

return true
}

func fetchKakaoAppKeyFromPrivacyInfo() -> String? {
guard let path = Bundle.main.path(forResource: "PrivacyInfo", ofType: "plist"),
let dict = NSDictionary(contentsOfFile: path) as? [String: AnyObject],
let appKey = dict["NATIVE_APP_KEY"] as? String else {
return nil
}
return appKey
}

// 카카오 로그인

// 카카오 로그인 URL 처리 (중복 제거)
func application(
_ app: UIApplication,
open url: URL,
Expand Down Expand Up @@ -117,7 +108,7 @@ extension AppDelegate: MessagingDelegate, UNUserNotificationCenterDelegate {
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken

Messaging.messaging().token { [weak self] token, error in
Messaging.messaging().token { token, error in
if let error = error {
print("Error fetching FCM registration token: \(error)")
} else if let token = token {
Comment on lines 112 to 114
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래와 같이 좀 더 간결하게 표현 가능합니다. (Swift 5.7부터 인걸로 알고 있어요.)

if let error {

} else if let token {

Expand Down
8 changes: 4 additions & 4 deletions KkuMulKum/Application/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
}

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
if let url = URLContexts.first?.url {
if (AuthApi.isKakaoTalkLoginUrl(url)) {
_ = AuthController.handleOpenUrl(url: url)
if let url = URLContexts.first?.url {
if (AuthApi.isKakaoTalkLoginUrl(url)) {
_ = AuthController.handleOpenUrl(url: url)
}
}
Comment on lines +42 to 46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

개인적인 의견입니다만, 저는 뎁스를 좀 지양하는 편이라 아래와 같이 표현도 가능해 보입니다.

// guard 문 사용
guard let url = URLContexts.first?.url, AuthApi.isKakaoTalkLoginUrl(url) else {
    return
}
_ = AuthController.handleOpenUrl(url: url)

// if 문 사용
if let url = URLContexts.first?.url, AuthApi.isKakaoTalkLoginUrl(url) {
    _ = AuthController.handleOpenUrl(url: url)
}

}
}

func application(
_ app: UIApplication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import AuthenticationServices

import KakaoSDKUser
import KakaoSDKAuth
import KakaoSDKCommon
import Moya
import FirebaseMessaging

Expand All @@ -29,13 +30,21 @@ class LoginViewModel: NSObject {
private let authInterceptor: AuthInterceptor
private let keychainAccessible: KeychainAccessible

private let kakaoAppKey: String

init(
provider: MoyaProvider<AuthTargetType> = MoyaProvider<AuthTargetType>(
plugins: [NetworkLoggerPlugin(configuration: .init(logOptions: .verbose))]
),
authService: AuthServiceProtocol = AuthService(),
keychainAccessible: KeychainAccessible = DefaultKeychainAccessible()
) {
if let appKey = Bundle.main.privacyInfo?["NATIVE_APP_KEY"] as? String {
self.kakaoAppKey = appKey
} else {
fatalError("Failed to load NATIVE_APP_KEY from PrivacyInfo.plist")
}

self.provider = provider
self.authService = authService
self.authInterceptor = AuthInterceptor(authService: authService, provider: provider)
Expand Down