Skip to content

Commit

Permalink
Merge pull request #411 from depromeet/fix/#410-fix-앱키-만료시-강제-업데이트-팝업-표출
Browse files Browse the repository at this point in the history
fix: App 버전에 따른 강제업데이트 팝업 표출 항목 버그 수정
  • Loading branch information
YuGeonHui authored Feb 15, 2024
2 parents ae04f48 + a309f3b commit ee6cf0f
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ final class HomeViewController: BaseViewController<HomeViewReactor>, UICollectio

override func viewDidLoad() {
super.viewDidLoad()

self.hideCameraButton(true)
UserDefaults.standard.inviteCode = nil
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -251,10 +253,10 @@ extension HomeViewController {
.bind(to: postCollectionView.rx.items(dataSource: createPostDataSource()))
.disposed(by: disposeBag)

postStream
.withUnretained(self)
.bind(onNext: { _ in App.Repository.member.postId.accept(UserDefaults.standard.postId) })
.disposed(by: disposeBag)
// postStream
// .withUnretained(self)
// .bind(onNext: { _ in App.Repository.member.postId.accept(UserDefaults.standard.postId) })
// .disposed(by: disposeBag)

reactor.pulse(\.$isRefreshEnd)
.withUnretained(self)
Expand All @@ -269,7 +271,9 @@ extension HomeViewController {

reactor.pulse(\.$postSection)
.withUnretained(self)
.bind(onNext: { $0.0.timerView.reactor = TimerDIContainer().makeReactor(isSelfUploaded: reactor.currentState.isSelfUploaded, isAllUploaded: reactor.currentState.isAllFamilyMembersUploaded)
.bind(onNext: {
$0.0.timerView.reactor = TimerDIContainer().makeReactor(isSelfUploaded: reactor.currentState.isSelfUploaded, isAllUploaded: reactor.currentState.isAllFamilyMembersUploaded)
App.Repository.member.postId.accept(UserDefaults.standard.postId)
})
.disposed(by: disposeBag)

Expand Down Expand Up @@ -352,7 +356,7 @@ extension HomeViewController {
case .main(let postListData):
if postListData.postId == postId {
let indexPath = IndexPath(row: index, section: 0)
self.navigationController?.pushViewController(PostListsDIContainer().makeViewController(postLists: reactor.currentState.postSection, selectedIndex: indexPath), animated: false)
self.navigationController?.pushViewController(PostListsDIContainer().makeViewController(postLists: reactor.currentState.postSection, selectedIndex: indexPath), animated: true)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ final class PostViewController: BaseViewController<PostReactor> {
}
.withUnretained(self)
.bind { owner, emoji in

print("emoji: \(emoji)")

let cameraViewController = CameraDIContainer(cameraType: .realEmoji, realEmojiType: emoji).makeViewController()
owner.navigationController?.pushViewController(cameraViewController, animated: true)
}.disposed(by: disposeBag)
Expand All @@ -69,6 +72,7 @@ final class PostViewController: BaseViewController<PostReactor> {
.disposed(by: disposeBag)

reactor.state.map { $0.isPop }
.filter { $0 }
.distinctUntilChanged()
.observe(on: MainScheduler.instance)
.withUnretained(self)
Expand Down Expand Up @@ -98,7 +102,7 @@ final class PostViewController: BaseViewController<PostReactor> {
.disposed(by: disposeBag)

didTapProfileImageNotificationHandler()
didTapSelectableCameraButtonNotifcationHandler()
// didTapSelectableCameraButtonNotifcationHandler()
}

override func setupUI() {
Expand Down Expand Up @@ -229,14 +233,14 @@ extension PostViewController {
}

extension PostViewController {
private func didTapSelectableCameraButtonNotifcationHandler() {
NotificationCenter.default
.rx.notification(.didTapSelectableCameraButton)
.withUnretained(self)
.bind { owner, _ in
owner.pushCameraViewController(cameraType: .realEmoji)
}.disposed(by: disposeBag)
}
// private func didTapSelectableCameraButtonNotifcationHandler() {
// NotificationCenter.default
// .rx.notification(.didTapSelectableCameraButton)
// .withUnretained(self)
// .bind { owner, _ in
// owner.pushCameraViewController(cameraType: .realEmoji)
// }.disposed(by: disposeBag)
// }

private func didTapProfileImageNotificationHandler() {
NotificationCenter.default
Expand Down
35 changes: 24 additions & 11 deletions 14th-team5-iOS/App/Sources/Presentation/Splash/SplashReactor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public final class SplashViewReactor: Reactor {

// MARK: - State
public struct State {
var memberInfo: MemberInfo?
var updatedNeeded: AppVersionInfo?
@Pulse var memberInfo: MemberInfo?
@Pulse var updatedNeeded: AppVersionInfo?
}

// MARK: - Properties
Expand All @@ -41,18 +41,30 @@ public final class SplashViewReactor: Reactor {

// MARK: - Mutate
public func mutate(action: Action) -> Observable<Mutation> {

switch action {
case .viewDidLoad:
return meRepository.getAppVersion()
.asObservable()
.flatMap { appVersionInfo in
Observable.concat([

guard let appVersionInfo = appVersionInfo else {
return Observable.just(Mutation.setUpdateNeeded(nil))
}

return Observable.concat([
Observable.just(Mutation.setUpdateNeeded(appVersionInfo)),
self.meRepository.getMemberInfo()
.asObservable()
.flatMap { memberInfo in
Observable.just(Mutation.setMemberInfo(memberInfo))

App.Repository.token.accessToken
.flatMap { token -> Observable<Mutation> in
guard let _ = token else {
return Observable.just(Mutation.setMemberInfo(nil))
}

return self.meRepository.getMemberInfo()
.asObservable()
.flatMap { memberInfo in
Observable.just(Mutation.setMemberInfo(memberInfo))
}
}
])
}
Expand All @@ -64,9 +76,10 @@ public final class SplashViewReactor: Reactor {
var newState = state
switch mutation {
case .setMemberInfo(let memberInfo):
App.Repository.member.memberID.accept(memberInfo?.memberId)
App.Repository.member.familyId.accept(memberInfo?.familyId)

if let memberInfo = memberInfo {
App.Repository.member.memberID.accept(memberInfo.memberId)
App.Repository.member.familyId.accept(memberInfo.familyId)
}
newState.memberInfo = memberInfo
case .setUpdateNeeded(let appVersion):
newState.updatedNeeded = appVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public final class SplashViewController: BaseViewController<SplashViewReactor> {

override public func bind(reactor: SplashViewReactor) {
Observable.just(())
.take(1)
.map { Reactor.Action.viewDidLoad }
.bind(to: reactor.action)
.disposed(by: disposeBag)
Expand All @@ -69,16 +68,16 @@ public final class SplashViewController: BaseViewController<SplashViewReactor> {
.bind(onNext: { $0.0.openAppStore() })
.disposed(by: disposeBag)

reactor.state.map { ($0.memberInfo, $0.updatedNeeded) }
.delay(.seconds(1), scheduler: Schedulers.main)
reactor.pulse(\.$memberInfo)
.skip(1)
.withUnretained(self)
.observe(on: Schedulers.main)
.filter { $0.1.1?.inService == true }
.bind(onNext: { $0.0.showNextPage(with: $0.1.0)})
.bind(onNext: { $0.0.showNextPage(with: $0.1)})
.disposed(by: disposeBag)

reactor.state.map { $0.updatedNeeded }
.compactMap { $0?.inService }
reactor.pulse(\.$updatedNeeded)
.skip(1)
.filter { $0 == nil }
.withUnretained(self)
.observe(on: Schedulers.main)
.bind(onNext: { $0.0.showUpdateAlert($0.1) })
Expand All @@ -93,48 +92,42 @@ public final class SplashViewController: BaseViewController<SplashViewReactor> {
}

private func showNextPage(with member: MemberInfo?) {

guard let sceneDelegate = UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate else { return }
let container: UINavigationController
var container: UINavigationController

if let _ = member?.familyId {
var container: UINavigationController
if UserDefaults.standard.finishTutorial {
if let _ = UserDefaults.standard.inviteCode {
container = UINavigationController(rootViewController: JoinedFamilyDIContainer().makeViewController())
} else {
container = UINavigationController(rootViewController: HomeDIContainer().makeViewController())
}
} else {
container = UINavigationController(rootViewController: OnBoardingDIContainer().makeViewController())
}
sceneDelegate.window?.rootViewController = container
sceneDelegate.window?.makeKeyAndVisible()
return
}

guard let isTemporary = App.Repository.token.accessToken.value?.isTemporaryToken else {
guard let member = member else {
container = UINavigationController(rootViewController: AccountSignInDIContainer().makeViewController())
sceneDelegate.window?.rootViewController = container
sceneDelegate.window?.makeKeyAndVisible()
return
}

if isTemporary {
let isTemporary = App.Repository.token.accessToken.value?.isTemporaryToken
if isTemporary == true {
container = UINavigationController(rootViewController: AccountSignUpDIContainer().makeViewController())
sceneDelegate.window?.rootViewController = container
sceneDelegate.window?.makeKeyAndVisible()
return
} else {
container = UINavigationController(rootViewController: OnBoardingDIContainer().makeViewController())
if let _ = member.familyId {
if UserDefaults.standard.inviteCode != nil {
container = UINavigationController(rootViewController: JoinedFamilyDIContainer().makeViewController())
} else {
container = UINavigationController(rootViewController: HomeDIContainer().makeViewController())
}
sceneDelegate.window?.rootViewController = container
sceneDelegate.window?.makeKeyAndVisible()
return
} else {
container = UINavigationController(rootViewController: OnBoardingDIContainer().makeViewController())
sceneDelegate.window?.rootViewController = container
sceneDelegate.window?.makeKeyAndVisible()
return
}
}

sceneDelegate.window?.rootViewController = container
sceneDelegate.window?.makeKeyAndVisible()
}

private func showUpdateAlert(_ inService: Bool) {
guard !inService else { return }
private func showUpdateAlert(_ appVersionInfo: AppVersionInfo?) {
let updateAlertController = UIAlertController(
title: "업데이트가 필요해요",
message: "더 나은 삐삐를 위해\n업데이트를 부탁드려요.",
Expand Down
2 changes: 1 addition & 1 deletion 14th-team5-iOS/Data/Sources/API/APIWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public final class BibbiRequestInterceptor: RequestInterceptor, BibbiRouterInter
completion(.success(urlRequest))
}

public func retry(_ request: Request, for session: Session, dueTo error: Error, retryCount: Int = 0, completion: @escaping (RetryResult) -> Void) {
public func retry(_ request: Request, for session: Session, dueTo error: Error, completion: @escaping (RetryResult) -> Void) {

guard let response = request.task?.response as? HTTPURLResponse, response.statusCode == 401 else {
completion(.doNotRetryWithError(error))
Expand Down
3 changes: 1 addition & 2 deletions 14th-team5-iOS/Data/Sources/Account/MeAPI/MeAPIWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ extension MeAPIWorker: MeRepositoryProtocol, JoinFamilyRepository {
}

private func getMemberInfo(spec: APISpec) -> Single<MemberInfo?> {

return request(spec: spec, headers: [BibbiAPI.Header.xAppKey])
return request(spec: spec)
.subscribe(on: Self.queue)
.do(onNext: {
if let str = String(data: $0.1, encoding: .utf8) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extension AccountSignInHelper {
guard let signOut = self?.signInHelper[sns]?.signOut() else { return Disposables.create() }
observer.onNext(signOut)


App.Repository.token.clearAccessToken()

return Disposables.create()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ final class KakaoSignInHelper: AccountSignInHelperType {
UserApi.shared.rx.logout()
.subscribe(onCompleted: {
// Token 제거시 확인
App.Repository.token.clearAccessToken()

debugPrint("Kakao logout completed!")
}, onError: { error in
debugPrint("Kakao logout error!")
Expand Down

0 comments on commit ee6cf0f

Please sign in to comment.