botId가 로컬저장되기전에 데이터를 요청하는 트러블 발생
botId가 로컬저장되기전에 데이터를 요청하는 트러블 발생
트러블 슈팅
원인
- 로그인 시 응답된
bot_id
를 저장한 후 그 id값으로 사용자의 데이터를 요청할 때 id값이UserDefaults
에 저장되기 전에 사용자의 데이터를 요청하는 문제 발생
해결
- sceneDelegate에서 앱 스키마를 통해 botId 쿼리값을 받아서
mainViewModel
의savedBotId PublishRelay
로 값을 전달
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let urlContext = URLContexts.first else { return }
let url = urlContext.url
guard let components = URLComponents(string: url.absoluteString) else { return }
// let host = components.host ?? "host 없음"
let items = components.queryItems ?? []
for i in items {
let queryName = i.name
guard let value = i.value else { continue }
switch queryName {
case "scuess":
if value == "true" {
loginViewModel.authSuccess.accept(true)
} else {
loginViewModel.authSuccess.accept(false)
}
case "bot_id":
Service.myPrint("bot_id response query") {
print(#function)
print(value)
}
//로컬에 이 값을 저장
SaveDataManager.setData(value: value, key: .botId)
// -----> savedBotId에 할당
mainViewModel.savedBotId.accept(value)
default:
break
} // switch
}
}
- MainViewModel - sabedBotId 감지해서
NodeApi.fetchNodes()
실행해서 데이터 가져오기
1
2
3
4
5
6
7
let savedBotId: PublishRelay<String> = PublishRelay()
savedBotId
.subscribe(onNext: { id in
self.nodeApi.fetchNodes()
})
.disposed(by: disposeBag)
This post is licensed under CC BY 4.0 by the author.