Skip to content

Commit da54a6a

Browse files
authored
Merge pull request #171 from Nexters/feature/#166-firebase-초기-설정-및-fcm-연결
[Feature/#166] firebase 초기 설정 및 fcm 연결
2 parents f2738eb + 6453c30 commit da54a6a

File tree

22 files changed

+336
-44
lines changed

22 files changed

+336
-44
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,6 @@ Derived/
6767
Tuist/.build
6868

6969
## XCConfig ##
70-
*.xcconfig
70+
*.xcconfig
71+
72+
*.plist

Plugins/DependencyPlugin/ProjectDescriptionHelpers/TargetDependency+SPM.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ public extension TargetDependency.SPM {
1919
static let KakaoSDKAuth: TargetDependency = .external(name: "KakaoSDKAuth")
2020
static let KakaoSDKUser: TargetDependency = .external(name: "KakaoSDKUser")
2121
static let Lottie: TargetDependency = .external(name: "Lottie")
22+
static let FirebaseAnalytics: TargetDependency = .external(name: "FirebaseAnalytics")
23+
static let FirebaseCrashlytics: TargetDependency = .external(name: "FirebaseCrashlytics")
24+
static let FirebaseMessaging: TargetDependency = .external(name: "FirebaseMessaging")
2225
}

Projects/App/Bottle.entitlements

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>aps-environment</key>
6+
<string>development</string>
57
<key>com.apple.developer.applesignin</key>
68
<array>
79
<string>Default</string>

Projects/App/Sources/AppDelegate.swift

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77

88
import SwiftUI
99

10+
import CoreLoggerInterface
1011
import Feature
1112

1213
import ComposableArchitecture
14+
import FirebaseCore
15+
import FirebaseMessaging
1316

14-
final class AppDelegate: UIResponder, UIApplicationDelegate {
17+
final class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate {
1518
var store = Store(
1619
initialState: AppFeature.State(),
1720
reducer: { AppFeature() }
@@ -21,6 +24,13 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
2124
_ application: UIApplication,
2225
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
2326
) -> Bool {
27+
FirebaseApp.configure()
28+
UIApplication.shared.registerForRemoteNotifications()
29+
UNUserNotificationCenter.current().delegate = self
30+
Messaging.messaging().delegate = self
31+
32+
application.registerForRemoteNotifications()
33+
2434
store.send(.appDelegate(.didFinishLunching))
2535
return true
2636
}
@@ -42,3 +52,30 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
4252
return configuration
4353
}
4454
}
55+
56+
extension AppDelegate: UNUserNotificationCenterDelegate {
57+
func messaging(
58+
_ messaging: Messaging,
59+
didReceiveRegistrationToken fcmToken: String?
60+
) {
61+
Log.debug("fcm token: \(fcmToken ?? "NO TOKEN")")
62+
if let fcmToken {
63+
// TODO: user defaults 설정 방법 변경
64+
UserDefaults.standard.set(fcmToken, forKey: "fcmToken")
65+
}
66+
}
67+
68+
func application(
69+
_ application: UIApplication,
70+
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
71+
) {
72+
Messaging.messaging().apnsToken = deviceToken
73+
}
74+
75+
func userNotificationCenter(
76+
_ center: UNUserNotificationCenter,
77+
willPresent notification: UNNotification
78+
) async -> UNNotificationPresentationOptions {
79+
return [.badge, .sound, .banner, .list]
80+
}
81+
}

Projects/Domain/Auth/Interface/Sources/API/AuthAPI.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public enum AuthAPI {
1515
case kakao(_ requestDTO: SignInRequestDTO)
1616
case apple(_ requestDTO: SignInRequestDTO)
1717
case withdraw
18-
case logout
18+
case logout(_ logOutRequestDTO: LogOutRequestDTO)
1919
case revoke
2020
}
2121

@@ -58,8 +58,8 @@ extension AuthAPI: BaseTargetType {
5858
return .requestJSONEncodable(requestDTO)
5959
case .withdraw:
6060
return .requestPlain
61-
case .logout:
62-
return .requestPlain
61+
case let .logout(logOutRequestDTO):
62+
return .requestJSONEncodable(logOutRequestDTO)
6363
case .revoke:
6464
return .requestPlain
6565
}

Projects/Domain/Auth/Interface/Sources/AuthClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public struct AuthClient {
2323
signInWithApple: @escaping () async throws -> SignInResponseDTO,
2424
saveToken: @escaping (Token) -> Void,
2525
checkTokenIsExist: @escaping () -> Bool,
26-
logout: @escaping () async throws -> Void,
2726
withdraw: @escaping () async throws -> Void,
27+
logout: @escaping () async throws -> Void,
2828
refreshAppleToken: @escaping () async throws -> AppleToken,
2929
revokeAppleLogin: @escaping () async throws -> Void,
3030
fetchAppleClientSecret: @escaping () async throws -> String
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// LogOutRequestDTO.swift
3+
// DomainAuthInterface
4+
//
5+
// Created by JongHoon on 8/21/24.
6+
//
7+
8+
public struct LogOutRequestDTO: Encodable {
9+
let fcmDeviceToken: String
10+
11+
public init(fcmDeviceToken: String) {
12+
self.fcmDeviceToken = fcmDeviceToken
13+
}
14+
}

Projects/Domain/Auth/Interface/Sources/DTO/Request/SignInRequestDTO.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ import Foundation
99

1010
public struct SignInRequestDTO: Encodable {
1111
public let code: String
12+
public let fcmDeviceToken: String
1213

13-
public init(code: String) {
14+
public init(
15+
code: String,
16+
fcmDeviceToken: String
17+
) {
1418
self.code = code
19+
self.fcmDeviceToken = fcmDeviceToken
1520
}
1621
}

Projects/Domain/Auth/Sources/AuthClient.swift

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Foundation
99

1010
import DomainAuthInterface
1111
import CoreNetwork
12+
import CoreLoggerInterface
1213

1314
import ComposableArchitecture
1415
import Moya
@@ -22,15 +23,25 @@ extension AuthClient: DependencyKey {
2223
return .init(
2324
signInWithKakao: {
2425
let accessToken = try await loginManager.signIn(loginType: .kakao)
25-
let data = SignInRequestDTO(code: accessToken)
26+
guard let fcmToken = UserDefaults.standard.string(forKey: "fcmToken")
27+
else {
28+
Log.fault("no fcm token")
29+
fatalError()
30+
}
31+
let data = SignInRequestDTO(code: accessToken, fcmDeviceToken: fcmToken)
2632
let responseData = try await networkManager.reqeust(api: .apiType(AuthAPI.kakao(data)), dto: SignInResponseDTO.self)
2733
return responseData
2834
},
2935

3036
signInWithApple: {
3137
// TODO: apple Login API로 수정
3238
let accessToken = try await loginManager.signIn(loginType: .apple)
33-
let data = SignInRequestDTO(code: accessToken)
39+
guard let fcmToken = UserDefaults.standard.string(forKey: "fcmToken")
40+
else {
41+
Log.fault("no fcm token")
42+
fatalError()
43+
}
44+
let data = SignInRequestDTO(code: accessToken, fcmDeviceToken: fcmToken)
3445
let responseData = try await networkManager.reqeust(api: .apiType(AuthAPI.apple(data)), dto: SignInResponseDTO.self)
3546
return responseData
3647
},
@@ -40,12 +51,17 @@ extension AuthClient: DependencyKey {
4051
checkTokenIsExist: {
4152
LocalAuthDataSourceImpl.checkTokeinIsExist()
4253
},
43-
logout: {
44-
try await networkManager.reqeust(api: .apiType(AuthAPI.logout))
45-
},
4654
withdraw: {
4755
try await networkManager.reqeust(api: .apiType(AuthAPI.withdraw))
4856
},
57+
logout: {
58+
guard let fcmToken = UserDefaults.standard.string(forKey: "fcmToken")
59+
else {
60+
Log.fault("no fcm token")
61+
return
62+
}
63+
try await networkManager.reqeust(api: .apiType(AuthAPI.logout(LogOutRequestDTO(fcmDeviceToken: fcmToken))))
64+
},
4965
refreshAppleToken: {
5066
let appleToken = try await networkManager.reqeust(api: .apiType(AppleAuthAPI.refreshToken), dto: AppleTokenResponseDTO.self).toDomain()
5167
return appleToken

Projects/Feature/ProfileSetup/Interface/Sources/IntroductionSetup/IntroductionSetupView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public struct IntroductionSetupView: View {
4242
.onLoad {
4343
store.send(.onLoad)
4444
}
45+
.scrollIndicators(.hidden)
4546
.ignoresSafeArea(.all, edges: .bottom)
4647
.toolbar(.hidden, for: .bottomBar)
4748
}

Projects/Feature/ProfileSetup/Interface/Sources/ProfileImageUpload/ProfileImageUploadView.swift

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,34 @@ public struct ProfileImageUploadView: View {
2424

2525
public var body: some View {
2626
ScrollView {
27-
titleView
28-
GeometryReader { geometry in
29-
WithPerceptionTracking {
30-
VStack(spacing: 0) {
31-
PhotosPicker(
32-
selection: $selectedItems,
33-
maxSelectionCount: 1,
34-
matching: .images
35-
) {
36-
imagePickerButton
37-
.frame(height: geometry.size.width)
38-
.padding(.bottom, .md)
39-
}
40-
.onChange(of: selectedItems) { item in
41-
handleSelectedPhotos(item)
42-
}
43-
doneButton
44-
}
27+
VStack(spacing: 0.0) {
28+
titleView
29+
30+
PhotosPicker(
31+
selection: $selectedItems,
32+
maxSelectionCount: 1,
33+
matching: .images
34+
) {
35+
imagePickerButton
36+
.frame(height: UIScreen.main.bounds.width - 16.0 * 2)
37+
.padding(.bottom, .md)
4538
}
46-
}
47-
.padding(.horizontal, .md)
48-
.setNavigationBar {
49-
makeNaivgationleftButton {
50-
store.send(.backButtonDidTapped)
39+
.onChange(of: selectedItems) { item in
40+
handleSelectedPhotos(item)
5141
}
42+
43+
doneButton
5244
}
53-
.toolbar(.hidden, for: .bottomBar)
45+
.padding(.bottom, .xl)
5446
}
47+
.padding(.horizontal, .md)
48+
.setNavigationBar {
49+
makeNaivgationleftButton {
50+
store.send(.backButtonDidTapped)
51+
}
52+
}
53+
.scrollIndicators(.hidden)
54+
.toolbar(.hidden, for: .bottomBar)
5555
}
5656
}
5757

@@ -63,7 +63,6 @@ private extension ProfileImageUploadView {
6363
caption: "가치관 문답을 마친 후 동의 하에 공개돼요"
6464
)
6565
.padding(.top, .xl)
66-
.padding(.horizontal, .md)
6766
.padding(.bottom, 32)
6867
}
6968

Projects/Feature/SandBeach/Interface/Sources/SandBeach/SandBeachFeatureInterface.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import DomainBottle
1414
import SharedUtilInterface
1515

1616
import ComposableArchitecture
17+
import FirebaseMessaging
1718

1819
@Reducer
1920
public struct SandBeachFeature {
@@ -63,6 +64,18 @@ extension SandBeachFeature {
6364
switch action {
6465
case .onAppear:
6566
state.isLoading = true
67+
let authOptions: UNAuthorizationOptions = [
68+
.alert,
69+
.badge,
70+
.sound
71+
]
72+
UNUserNotificationCenter.current().requestAuthorization(
73+
options: authOptions,
74+
completionHandler: { _, error in
75+
if let error = error {
76+
Log.error(error)
77+
}
78+
})
6679

6780
return .run { send in
6881
let isExsit = try await profileClient.checkExistIntroduction()

Projects/Feature/Sources/SplashView/SplashView.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ public struct SplashView: View {
1313
public var body: some View {
1414
ZStack {
1515
ColorToken.container(.pressed).color
16-
.ignoresSafeArea()
16+
.ignoresSafeArea()
17+
18+
Image.BottleImageSystem.illustraition(.splash).image
1719
}
20+
.ignoresSafeArea()
1821
}
1922
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "icon_splash.svg",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}
Lines changed: 48 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)