Grant Permissions
ROOK SDK requires that the user explicitly grant permissions to access and extract data from Apple Health.
Request Permissions
RookConnectPermissionsManager
is a class that contains functions useful for achieving this. The primary function, requestAllPermissions
, requests permissions to access data. This function will display a screen requesting the necessary permissions.
The callback of each method returns a boolean: true
if the permission window was successfully presented, or false
with an optional error if the window was not presented properly. This value does not indicate whether the user actually granted permission. Please note that Apple Health does not allow checking the status of permissions for types requested to be read. If the user does not allow data type reading, either by mistake or on purpose, it will simply appear as if there is no data of the requested type in the HealthKit store. Any further changes must be performed by the user through the Apple Health application.
We recommend you to add a view for this:
import SwiftUI
struct PermissionsView: View {
@StateObject var viewModel: PermissionsViewModel = PermissionsViewModel()
var body: some View {
VStack {
if viewModel.isLoading {
ProgressView()
} else {
Button(action: {
viewModel.requestPermission()
}, label: {
Text("get Permissions")
.foregroundColor(.white)
.font(.system(size: 16, weight: .bold))
.frame(width: 250, height: 50)
.background(Color.red)
.cornerRadius(12)
.padding(21)
})
}
}
}
}
import Foundation
import RookSDK
class SyncYesterdayViewModel: ObservableObject {
private let permissionManger: RookConnectPermissionsManager = RookConnectPermissionsManager()
@Published var isLoading: Bool = false
func requestPermission() {
self.isLoading = true
permissionManger.requestAllPermissions { [weak self] _ in
DispatchQueue.main.async {
self?.isLoading = false
}
}
}
}