|
|
@@ -10,35 +10,29 @@ extension AppleHealthKit {
|
|
|
|
|
|
override func subscribe() {
|
|
|
useAppleHealth = settingsManager.settings.useAppleHealth
|
|
|
- needShowInformationTextForSetPermissions = settingsManager.settings.needShowInformationTextForSetPermissions
|
|
|
|
|
|
- subscribeSetting(\.needShowInformationTextForSetPermissions, on: $needShowInformationTextForSetPermissions) { _ in }
|
|
|
+ subscribeSetting(\.useAppleHealth, on: $useAppleHealth) {
|
|
|
+ useAppleHealth = $0
|
|
|
+ } didSet: { [weak self] value in
|
|
|
+ guard let self = self else { return }
|
|
|
|
|
|
- $useAppleHealth
|
|
|
- .removeDuplicates()
|
|
|
- .sink { [weak self] value in
|
|
|
- guard let self = self else { return }
|
|
|
- guard value else {
|
|
|
- self.settingsManager.settings.useAppleHealth = false
|
|
|
- self.needShowInformationTextForSetPermissions = false
|
|
|
+ guard value else {
|
|
|
+ self.needShowInformationTextForSetPermissions = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ self.healthKitManager.requestPermission { status, error in
|
|
|
+ guard error == nil else {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- self.healthKitManager.requestPermission { status, error in
|
|
|
- guard error == nil else {
|
|
|
- return
|
|
|
- }
|
|
|
- self.settingsManager.settings.useAppleHealth = status
|
|
|
- self.healthKitManager.enableBackgroundDelivery()
|
|
|
- self.healthKitManager.createObserver()
|
|
|
- DispatchQueue.main.async {
|
|
|
- if !self.healthKitManager.areAllowAllPermissions {
|
|
|
- self.needShowInformationTextForSetPermissions = true
|
|
|
- }
|
|
|
- }
|
|
|
+ self.healthKitManager.enableBackgroundDelivery()
|
|
|
+ self.healthKitManager.createObserver()
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ self.needShowInformationTextForSetPermissions = !self.healthKitManager.areAllowAllPermissions
|
|
|
}
|
|
|
}
|
|
|
- .store(in: &lifetime)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|