Skip to content

Commit 333833b

Browse files
committed
Health permission hot fix
(cherry picked from commit 19ce5aa)
1 parent 652c22e commit 333833b

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let package = Package(
2323
.target(
2424
name: "PermissionsSwiftUI",
2525
dependencies: [],
26-
exclude: ["Tests/PermissionsSwiftUITests/__Snapshots__"]
26+
exclude: ["../../Tests/PermissionsSwiftUITests/__Snapshots__"]
2727
),
2828
.testTarget(
2929
name: "PermissionsSwiftUITests",

Sources/PermissionsSwiftUI/Model/PermissionTypeGetSet.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ extension PermissionType:PermissionTypeProtocol{
147147
JMSpeechPermissionManager.shared.requestPermission{
148148
isPermissionGranted($0)
149149
}
150-
case .health:
151-
JMHealthPermissionManager.shared.requestPermission{
150+
case .health(let HKPermissions):
151+
JMHealthPermissionManager.shared.requestPermission(for: HKPermissions){
152152
isPermissionGranted($0)
153153
}
154154
}

Sources/PermissionsSwiftUI/Model/Permissions/JMHealthPermissionManager.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ class JMHealthPermissionManager{
1313
static let shared = JMHealthPermissionManager()
1414
typealias JMBluetoothPermissionHandler = (Bool) -> Void?
1515

16-
func requestPermission(completion: @escaping (Bool) -> Void?) {
16+
func requestPermission(for HKPermissions:Set<HKSampleType>, completion: @escaping (Bool) -> Void?) {
1717
guard HKHealthStore.isHealthDataAvailable() else {
18-
print("PermissionsSwiftUI - Health data is not available")
18+
print("PermissionsSwiftUI - Health data is not available")
1919
completion(false)
2020
return
2121
}
22-
let allTypes = Set([HKObjectType.workoutType(), HKObjectType.quantityType(forIdentifier: .dietaryFatTotal)!])
23-
healthStore.requestAuthorization(toShare: allTypes, read: allTypes){authorized, error in
22+
healthStore.requestAuthorization(toShare: HKPermissions, read: HKPermissions){authorized, error in
2423
guard error == nil else{
2524
print("PermissionSwiftUI - \(String(describing: error))")
2625
completion(false)

0 commit comments

Comments
 (0)