hasPermissions

actual suspend fun hasPermissions(context: Any?): Boolean

Checks if all necessary permissions for accessing health data have been granted by the user.

This function should be called before attempting to access any health data to ensure that the application has the required permissions.

Return

true if all required permissions are granted, false otherwise.

Parameters

context

An optional platform-specific context. On Android this is an Activity / Context used by Health Connect; on iOS / watchOS it is unused and may be nil.

Throws

if an error occurs during the permission check process.

Android (Kotlin)

lifecycleScope.launch {
try {
if (AFCore.healthTracking().hasPermissions(context = activity)) {
startSyncing()
} else {
AFCore.healthTracking().requestPermissions(context = activity)
}
} catch (t: Throwable) {
showError("Could not check health permissions: ${t.message}")
}
}

iOS (Swift)

Task {
do {
if try await AFCore.shared.healthTracking().hasPermissions(context: nil) {
self.startSyncing()
} else {
_ = try await AFCore.shared.healthTracking().requestPermissions(context: nil)
}
} catch {
self.showError("Could not check health permissions: \\(error.localizedDescription)")
}
}
actual suspend fun hasPermissions(context: Any?): Boolean

Checks if all necessary permissions for accessing health data have been granted by the user.

This function should be called before attempting to access any health data to ensure that the application has the required permissions.

Return

true if all required permissions are granted, false otherwise.

Parameters

context

An optional platform-specific context. On Android this is an Activity / Context used by Health Connect; on iOS / watchOS it is unused and may be nil.

Throws

if an error occurs during the permission check process.

Android (Kotlin)

lifecycleScope.launch {
try {
if (AFCore.healthTracking().hasPermissions(context = activity)) {
startSyncing()
} else {
AFCore.healthTracking().requestPermissions(context = activity)
}
} catch (t: Throwable) {
showError("Could not check health permissions: ${t.message}")
}
}

iOS (Swift)

Task {
do {
if try await AFCore.shared.healthTracking().hasPermissions(context: nil) {
self.startSyncing()
} else {
_ = try await AFCore.shared.healthTracking().requestPermissions(context: nil)
}
} catch {
self.showError("Could not check health permissions: \\(error.localizedDescription)")
}
}
actual suspend fun hasPermissions(context: Any?): Boolean

Checks if all necessary permissions for accessing health data have been granted by the user.

This function should be called before attempting to access any health data to ensure that the application has the required permissions.

Return

true if all required permissions are granted, false otherwise.

Parameters

context

An optional platform-specific context. On Android this is an Activity / Context used by Health Connect; on iOS / watchOS it is unused and may be nil.

Throws

if an error occurs during the permission check process.

Android (Kotlin)

lifecycleScope.launch {
try {
if (AFCore.healthTracking().hasPermissions(context = activity)) {
startSyncing()
} else {
AFCore.healthTracking().requestPermissions(context = activity)
}
} catch (t: Throwable) {
showError("Could not check health permissions: ${t.message}")
}
}

iOS (Swift)

Task {
do {
if try await AFCore.shared.healthTracking().hasPermissions(context: nil) {
self.startSyncing()
} else {
_ = try await AFCore.shared.healthTracking().requestPermissions(context: nil)
}
} catch {
self.showError("Could not check health permissions: \\(error.localizedDescription)")
}
}