Created
November 27, 2019 11:17
-
-
Save KaneCheshire/7cd6b1e775630512fb9e84c66b745cc5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import HealthKit | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
private let store = HKHealthStore() | |
private let falls = HKObjectType.quantityType(forIdentifier: .numberOfTimesFallen)! | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
requestPermissionToWriteFalls() | |
return true | |
} | |
private func requestPermissionToWriteFalls() { | |
store.requestAuthorization(toShare: [falls], read: nil) { success, error in | |
print("Finished requesting authorization", success, error) | |
self.addAFall() | |
} | |
} | |
private func addAFall() { | |
let quantity = HKQuantity(unit: .count(), doubleValue: 1) | |
let sample = HKQuantitySample(type: falls, quantity: quantity, start: Date(), end: Date()) | |
store.save(sample) { success, error in | |
print("Finished saving fall", success, error) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment