Stabilize iOS/watchOS/tvOS apps and add cross-platform audit remediation
This commit is contained in:
@@ -7,10 +7,12 @@
|
||||
|
||||
import WatchKit
|
||||
import HealthKit
|
||||
import os
|
||||
|
||||
class WatchDelegate: NSObject, WKApplicationDelegate {
|
||||
private let logger = Logger(subsystem: "com.werkout.watch", category: "lifecycle")
|
||||
func applicationDidFinishLaunching() {
|
||||
autorizeHealthKit()
|
||||
authorizeHealthKit()
|
||||
}
|
||||
|
||||
func applicationDidBecomeActive() {
|
||||
@@ -25,17 +27,24 @@ class WatchDelegate: NSObject, WKApplicationDelegate {
|
||||
// WatchWorkout.shared.startWorkout()
|
||||
}
|
||||
|
||||
func autorizeHealthKit() {
|
||||
let healthKitTypes: Set = [
|
||||
HKObjectType.quantityType(forIdentifier: .heartRate)!,
|
||||
HKObjectType.quantityType(forIdentifier: .activeEnergyBurned)!,
|
||||
HKObjectType.quantityType(forIdentifier: .oxygenSaturation)!,
|
||||
func authorizeHealthKit() {
|
||||
guard let heartRateType = HKObjectType.quantityType(forIdentifier: .heartRate),
|
||||
let activeEnergyType = HKObjectType.quantityType(forIdentifier: .activeEnergyBurned),
|
||||
let oxygenSaturationType = HKObjectType.quantityType(forIdentifier: .oxygenSaturation) else {
|
||||
logger.error("Missing required HealthKit quantity types during authorization")
|
||||
return
|
||||
}
|
||||
|
||||
let healthKitTypes: Set<HKObjectType> = [
|
||||
heartRateType,
|
||||
activeEnergyType,
|
||||
oxygenSaturationType,
|
||||
HKObjectType.activitySummaryType(),
|
||||
HKQuantityType.workoutType()
|
||||
]
|
||||
HKHealthStore().requestAuthorization(toShare: nil, read: healthKitTypes) { (succ, error) in
|
||||
if !succ {
|
||||
fatalError("Error requesting authorization from health store: \(String(describing: error)))")
|
||||
self.logger.error("HealthKit authorization failed: \(String(describing: error), privacy: .public)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user