Skip to content

Instantly share code, notes, and snippets.

@paulw11
Last active January 29, 2018 23:50
Show Gist options
  • Save paulw11/11cc3da5b9502a785073a5cd3c98ef2d to your computer and use it in GitHub Desktop.
Save paulw11/11cc3da5b9502a785073a5cd3c98ef2d to your computer and use it in GitHub Desktop.
HKTest
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSHealthShareUsageDescription</key>
<string>test healthkit</string>
<key>NSHealthUpdateUsageDescription</key>
<string>test healthkit</string>
</dict>
</plist>
//
// ViewController.swift
// HKTest
//
// Created by Paul Wilkinson on 30/1/18.
// Copyright © 2018 Paul Wilkinson. All rights reserved.
//
import UIKit
import HealthKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidAppear(_ animated: Bool) {
super .viewDidAppear(animated)
self.requestHealthkit()
}
public func requestHealthkit() {
let healthStore = HKHealthStore()
var shareTypes = Set<HKSampleType>()
shareTypes.insert(HKSampleType.workoutType())
var readTypes = Set<HKObjectType>()
readTypes.insert(HKObjectType.workoutType())
healthStore.requestAuthorization(toShare: shareTypes, read: readTypes) { (success, error) -> Void in
if success {
print("[HealthKit] request Authorization succeed!")
} else {
print("[HealthKit] request Authorization failed!")
}
if let error = error { print("[HealthKit] An error occurred: \(error)") }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment