响应式 deviceToken

This commit is contained in:
Fin 2022-03-23 14:41:06 +08:00
parent 682856aa10
commit 1aad039272
3 changed files with 3 additions and 5 deletions

View File

@ -104,7 +104,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let deviceTokenString = deviceToken.map { String(format: "%02.2hhx", $0) }.joined() let deviceTokenString = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
Settings[.deviceToken] = deviceTokenString Client.shared.deviceToken.accept(deviceTokenString)
// //
Client.shared.bindDeviceToken() Client.shared.bindDeviceToken()

View File

@ -15,8 +15,6 @@ enum BarkSettingKey: String {
case servers = "me.fin.bark.servers" case servers = "me.fin.bark.servers"
case currentServer = "me.fin.bark.servers.current" case currentServer = "me.fin.bark.servers.current"
case deviceToken = "me.fin.bark.deviceToken"
case selectedViewControllerIndex = "me.fin.bark.selectedViewControllerIndex" case selectedViewControllerIndex = "me.fin.bark.selectedViewControllerIndex"
} }

View File

@ -57,12 +57,12 @@ class Client: NSObject {
case unRegister case unRegister
case serverError case serverError
} }
var deviceToken = BehaviorRelay<String?>(value: nil)
var state = BehaviorRelay<ClienState>(value: .ok) var state = BehaviorRelay<ClienState>(value: .ok)
var dispose: Disposable? var dispose: Disposable?
func bindDeviceToken() { func bindDeviceToken() {
if let token = Settings[.deviceToken], token.count > 0 { if let token = deviceToken.value, token.count > 0 {
dispose?.dispose() dispose?.dispose()
dispose = BarkApi.provider dispose = BarkApi.provider