From 1aad0392723d516f81e2f5eca2a33fc29de217f5 Mon Sep 17 00:00:00 2001 From: Fin Date: Wed, 23 Mar 2022 14:41:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=93=8D=E5=BA=94=E5=BC=8F=20deviceToken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bark/AppDelegate.swift | 2 +- Common/BarkSettings.swift | 2 -- Common/Client.swift | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Bark/AppDelegate.swift b/Bark/AppDelegate.swift index a91b312..e906718 100644 --- a/Bark/AppDelegate.swift +++ b/Bark/AppDelegate.swift @@ -104,7 +104,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { let deviceTokenString = deviceToken.map { String(format: "%02.2hhx", $0) }.joined() - Settings[.deviceToken] = deviceTokenString + Client.shared.deviceToken.accept(deviceTokenString) // 注册设备 Client.shared.bindDeviceToken() diff --git a/Common/BarkSettings.swift b/Common/BarkSettings.swift index f858f42..21a96cf 100644 --- a/Common/BarkSettings.swift +++ b/Common/BarkSettings.swift @@ -15,8 +15,6 @@ enum BarkSettingKey: String { case servers = "me.fin.bark.servers" case currentServer = "me.fin.bark.servers.current" - case deviceToken = "me.fin.bark.deviceToken" - case selectedViewControllerIndex = "me.fin.bark.selectedViewControllerIndex" } diff --git a/Common/Client.swift b/Common/Client.swift index ee714eb..eab73b6 100644 --- a/Common/Client.swift +++ b/Common/Client.swift @@ -57,12 +57,12 @@ class Client: NSObject { case unRegister case serverError } - + var deviceToken = BehaviorRelay(value: nil) var state = BehaviorRelay(value: .ok) var dispose: Disposable? func bindDeviceToken() { - if let token = Settings[.deviceToken], token.count > 0 { + if let token = deviceToken.value, token.count > 0 { dispose?.dispose() dispose = BarkApi.provider