Skip to content

Commit

Permalink
Merge pull request #277 from PLUB2022/feat/186-FCM/Tokens
Browse files Browse the repository at this point in the history
로그인 - FCM 기능 추가
  • Loading branch information
WhiteHyun authored Apr 11, 2023
2 parents bcce59d + 231f228 commit 115f1d4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
23 changes: 23 additions & 0 deletions PLUB/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UIKit
import GoogleSignIn
import KakaoSDKCommon
import FirebaseCore
import FirebaseMessaging

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -24,6 +25,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
)

FirebaseApp.configure()
configureCloudMessaging(application)

setupNavigationBarStyle()

Expand All @@ -39,6 +41,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
}

// MARK: Configuration Methods

private func configureCloudMessaging(_ application: UIApplication) {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { _, _ in

}

application.registerForRemoteNotifications()

Messaging.messaging().delegate = self
}

private func setupNavigationBarStyle() {
let appearance = UINavigationBarAppearance()

Expand All @@ -60,3 +74,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

// MARK: - MessagingDelegate

extension AppDelegate: MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
guard let fcmToken else { return }
Log.notice(fcmToken)
UserManager.shared.set(fcmToken: fcmToken)
}
}
9 changes: 9 additions & 0 deletions PLUB/Configuration/Manager/UserManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ final class UserManager {
@KeyChainWrapper<String>(key: "refreshToken")
private(set) var refreshToken

@KeyChainWrapper<String>(key: "fcmToken")
private(set) var fcmToken

// MARK: - Social Login Type

@UserDefaultsWrapper<SocialType>(key: "socialType")
Expand Down Expand Up @@ -61,6 +64,11 @@ extension UserManager {
self.signToken = signToken
}

/// 플럽 푸시 알림에 필요한 `firebase cloud messaging Token`을 세팅합니다.
func set(fcmToken: String) {
self.fcmToken = fcmToken
}

/// 소셜로그인 타입을 세팅합니다.
/// - Parameter socialType: 소셜로그인 타입(애플, 구글, 카카오)
func set(socialType: SocialType) {
Expand All @@ -77,6 +85,7 @@ extension UserManager {
accessToken = nil
refreshToken = nil
signToken = nil
fcmToken = nil
socialType = nil
}

Expand Down
3 changes: 3 additions & 0 deletions PLUB/Sources/Models/Auth/Request/SignInRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import Foundation
/// 소셜 로그인 요청 모델
struct SignInRequest: Codable {

/// Firebase Cloud Messaging Token
let fcmToken: String

/// 액세스 토큰(카카오, 애플)
/// 애플의 경우 identityToken을 해당 값으로 처리해야합니다.
let accessToken: String?
Expand Down
6 changes: 6 additions & 0 deletions PLUB/Sources/Models/Auth/Request/SignUpRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import Then

/// 회원가입 요청 모델
struct SignUpRequest: Codable {

/// Firebase Cloud Messaging Token
let fcmToken: String

/// sign token
var signToken: String

Expand Down Expand Up @@ -48,6 +52,7 @@ struct SignUpRequest: Codable {
var marketing: Bool

init() {
fcmToken = UserManager.shared.fcmToken!
signToken = UserManager.shared.signToken!
categoryList = []
birthday = ""
Expand All @@ -66,6 +71,7 @@ struct SignUpRequest: Codable {

extension SignUpRequest {
enum CodingKeys: String, CodingKey {
case fcmToken
case signToken
case categoryList
case profileImageLink = "profileImage"
Expand Down
9 changes: 8 additions & 1 deletion PLUB/Sources/Network/Services/AuthService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ extension AuthService {
authorizationCode: String?
) -> PLUBResult<SignInResponse> {
return sendRequest(
AuthRouter.socialLogin(SignInRequest(accessToken: token, authorizationCode: authorizationCode, socialType: socialType)),
AuthRouter.socialLogin(
SignInRequest(
fcmToken: UserManager.shared.fcmToken!,
accessToken: token,
authorizationCode: authorizationCode,
socialType: socialType
)
),
type: SignInResponse.self
)
}
Expand Down

0 comments on commit 115f1d4

Please sign in to comment.