Skip to content
This repository has been archived by the owner on Dec 7, 2024. It is now read-only.

Commit

Permalink
🚑 :: deviceToken
Browse files Browse the repository at this point in the history
  • Loading branch information
baekteun committed Mar 15, 2023
1 parent 744bf1d commit f40b16e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Service/Sources/Data/DataSource/Remote/DataSource/AuthRemote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ final class AuthRemote: BaseRemote<AuthAPI> {
private override init() {}

func login(code: String) -> Single<TokenDTO> {
return request(.login(code: code, deviceToken: Messaging.messaging().fcmToken ?? ""))
return fetchDeviceToken()
.flatMap { self.request(.login(code: code, deviceToken: $0)) }
.map(TokenDTO.self)
}

func refresh() -> Completable {
return request(.refresh(deviceToken: Messaging.messaging().fcmToken ?? ""))
return fetchDeviceToken()
.flatMap { self.request(.refresh(deviceToken: $0)) }
.asCompletable()
}

Expand All @@ -20,3 +22,15 @@ final class AuthRemote: BaseRemote<AuthAPI> {
.asCompletable()
}
}

private extension AuthRemote {
/// 디바이스 토큰 가져오는 API
func fetchDeviceToken() -> Single<String> {
return Single<String>.create { single in
Messaging.messaging().token { token, _ in
single(.success(token ?? ""))
}
return Disposables.create()
}
}
}
2 changes: 2 additions & 0 deletions iOS/Sources/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ extension AppDelegate: UNUserNotificationCenterDelegate, MessagingDelegate {
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
Messaging.messaging().apnsToken = deviceToken
_ = AppDelegate.container.resolve(CheckIsLoginedUseCase.self)!
.execute()
}

func messaging(
Expand Down

0 comments on commit f40b16e

Please sign in to comment.