Last active
January 29, 2018 23:50
-
-
Save paulw11/11cc3da5b9502a785073a5cd3c98ef2d to your computer and use it in GitHub Desktop.
HKTest
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
<?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> |
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
// | |
// 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