mirror of
https://github.com/Finb/Bark.git
synced 2025-12-08 21:36:01 +00:00
响应式 deviceToken
This commit is contained in:
parent
682856aa10
commit
1aad039272
@ -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()
|
||||||
|
|||||||
@ -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"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user