Skip to content

Commit

Permalink
Report data to HealthKit.
Browse files Browse the repository at this point in the history
  • Loading branch information
imdanielsp committed Apr 19, 2017
1 parent b5a3c48 commit b42ca80
Show file tree
Hide file tree
Showing 35 changed files with 394 additions and 123 deletions.
Binary file added IconProj.pcvd
Binary file not shown.
8 changes: 4 additions & 4 deletions Keep Standing.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
6E1B3A0E1EA6BEF70089E1BF /* RoundedButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E1B3A0D1EA6BEF70089E1BF /* RoundedButtonView.swift */; };
6E365D791EA6940D0076D798 /* IntroVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E365D781EA6940D0076D798 /* IntroVC.swift */; };
6E365D7B1EA694EF0076D798 /* WeightPickerManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E365D7A1EA694EF0076D798 /* WeightPickerManager.swift */; };
6E54F69A1EA5B0E300CA6F33 /* UserManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E54F6991EA5B0E300CA6F33 /* UserManager.swift */; };
6E54F69A1EA5B0E300CA6F33 /* UserDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E54F6991EA5B0E300CA6F33 /* UserDataManager.swift */; };
6E54F69C1EA5B9AB00CA6F33 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E54F69B1EA5B9AB00CA6F33 /* User.swift */; };
6E54F69E1EA5C25C00CA6F33 /* DataError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E54F69D1EA5C25C00CA6F33 /* DataError.swift */; };
6EF33AD11EA4847000A82780 /* HealthManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EF33AD01EA4847000A82780 /* HealthManager.swift */; };
Expand All @@ -29,7 +29,7 @@
6E1B3A0D1EA6BEF70089E1BF /* RoundedButtonView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoundedButtonView.swift; sourceTree = "<group>"; };
6E365D781EA6940D0076D798 /* IntroVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IntroVC.swift; sourceTree = "<group>"; };
6E365D7A1EA694EF0076D798 /* WeightPickerManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeightPickerManager.swift; sourceTree = "<group>"; };
6E54F6991EA5B0E300CA6F33 /* UserManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserManager.swift; sourceTree = "<group>"; };
6E54F6991EA5B0E300CA6F33 /* UserDataManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserDataManager.swift; sourceTree = "<group>"; };
6E54F69B1EA5B9AB00CA6F33 /* User.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
6E54F69D1EA5C25C00CA6F33 /* DataError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataError.swift; sourceTree = "<group>"; };
6EF33AD01EA4847000A82780 /* HealthManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HealthManager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -102,7 +102,7 @@
children = (
6EF33AD01EA4847000A82780 /* HealthManager.swift */,
6EF33AD71EA487B700A82780 /* Type.swift */,
6E54F6991EA5B0E300CA6F33 /* UserManager.swift */,
6E54F6991EA5B0E300CA6F33 /* UserDataManager.swift */,
6E54F69D1EA5C25C00CA6F33 /* DataError.swift */,
6E365D7A1EA694EF0076D798 /* WeightPickerManager.swift */,
);
Expand Down Expand Up @@ -290,7 +290,7 @@
6EF9F4F31E98AB5000592572 /* MainVC.swift in Sources */,
6E54F69E1EA5C25C00CA6F33 /* DataError.swift in Sources */,
6E365D791EA6940D0076D798 /* IntroVC.swift in Sources */,
6E54F69A1EA5B0E300CA6F33 /* UserManager.swift in Sources */,
6E54F69A1EA5B0E300CA6F33 /* UserDataManager.swift in Sources */,
6EF9F4F11E98AB5000592572 /* AppDelegate.swift in Sources */,
6E1B3A0E1EA6BEF70089E1BF /* RoundedButtonView.swift in Sources */,
6E365D7B1EA694EF0076D798 /* WeightPickerManager.swift in Sources */,
Expand Down
220 changes: 174 additions & 46 deletions Keep Standing/Assets.xcassets/AppIcon.appiconset/Contents.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,48 +1,176 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
"images":[
{
"idiom":"iphone",
"size":"20x20",
"scale":"2x",
"filename":"[email protected]"
},
{
"idiom":"iphone",
"size":"20x20",
"scale":"3x",
"filename":"[email protected]"
},
{
"idiom":"iphone",
"size":"29x29",
"scale":"1x",
"filename":"[email protected]"
},
{
"idiom":"iphone",
"size":"29x29",
"scale":"2x",
"filename":"[email protected]"
},
{
"idiom":"iphone",
"size":"29x29",
"scale":"3x",
"filename":"[email protected]"
},
{
"idiom":"iphone",
"size":"40x40",
"scale":"1x",
"filename":"[email protected]"
},
{
"idiom":"iphone",
"size":"40x40",
"scale":"2x",
"filename":"[email protected]"
},
{
"idiom":"iphone",
"size":"40x40",
"scale":"3x",
"filename":"[email protected]"
},
{
"idiom":"iphone",
"size":"57x57",
"scale":"1x",
"filename":"[email protected]"
},
{
"idiom":"iphone",
"size":"57x57",
"scale":"2x",
"filename":"[email protected]"
},
{
"idiom":"iphone",
"size":"60x60",
"scale":"1x",
"filename":"[email protected]"
},
{
"idiom":"iphone",
"size":"60x60",
"scale":"2x",
"filename":"[email protected]"
},
{
"idiom":"iphone",
"size":"60x60",
"scale":"3x",
"filename":"[email protected]"
},
{
"idiom":"iphone",
"size":"76x76",
"scale":"1x",
"filename":"[email protected]"
},
{
"idiom":"ipad",
"size":"20x20",
"scale":"1x",
"filename":"[email protected]"
},
{
"idiom":"ipad",
"size":"20x20",
"scale":"2x",
"filename":"[email protected]"
},
{
"idiom":"ipad",
"size":"29x29",
"scale":"1x",
"filename":"[email protected]"
},
{
"idiom":"ipad",
"size":"29x29",
"scale":"2x",
"filename":"[email protected]"
},
{
"idiom":"ipad",
"size":"40x40",
"scale":"1x",
"filename":"[email protected]"
},
{
"idiom":"ipad",
"size":"40x40",
"scale":"2x",
"filename":"[email protected]"
},
{
"size" : "50x50",
"idiom" : "ipad",
"filename" : "[email protected]",
"scale" : "1x"
},
{
"size" : "50x50",
"idiom" : "ipad",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom":"ipad",
"size":"72x72",
"scale":"1x",
"filename":"[email protected]"
},
{
"idiom":"ipad",
"size":"72x72",
"scale":"2x",
"filename":"[email protected]"
},
{
"idiom":"ipad",
"size":"76x76",
"scale":"1x",
"filename":"[email protected]"
},
{
"idiom":"ipad",
"size":"76x76",
"scale":"2x",
"filename":"[email protected]"
},
{
"idiom":"ipad",
"size":"76x76",
"scale":"3x",
"filename":"[email protected]"
},
{
"idiom":"ipad",
"size":"83.5x83.5",
"scale":"2x",
"filename":"[email protected]"
}
],
"info":{
"version":1,
"author":"makeappicon"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Keep Standing/Assets.xcassets/icon.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Canvas 1-1.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Canvas 1.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Canvas 1-2.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
45 changes: 39 additions & 6 deletions Keep Standing/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12118" systemVersion="16F60a" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina5_5" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -14,14 +19,42 @@
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="icon" translatesAutoresizingMaskIntoConstraints="NO" id="vJF-mm-6bC">
<rect key="frame" x="41" y="218" width="332" height="300"/>
<constraints>
<constraint firstAttribute="height" constant="300" id="0wC-JJ-Yze"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="KEEP STANDING" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fdA-Ep-5R6">
<rect key="frame" x="35" y="60" width="344" height="57"/>
<constraints>
<constraint firstAttribute="height" constant="57" id="LI7-nv-WQI"/>
</constraints>
<fontDescription key="fontDescription" name="HelveticaNeue-CondensedBold" family="Helvetica Neue" pointSize="38"/>
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.21445584300000001" green="0.23735129830000001" blue="0.2372089922" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="vJF-mm-6bC" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="EIN-aE-9b4"/>
<constraint firstAttribute="trailing" secondItem="fdA-Ep-5R6" secondAttribute="trailing" constant="35" id="QgV-ej-8Jh"/>
<constraint firstItem="vJF-mm-6bC" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leadingMargin" constant="21" id="bUK-n0-6sV"/>
<constraint firstAttribute="trailingMargin" secondItem="vJF-mm-6bC" secondAttribute="trailing" constant="21" id="bZA-Cs-o93"/>
<constraint firstItem="fdA-Ep-5R6" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" constant="35" id="lFg-DQ-wQf"/>
<constraint firstItem="fdA-Ep-5R6" firstAttribute="top" secondItem="Ze5-6b-2t3" secondAttribute="topMargin" constant="60" id="n6g-j3-NOp"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
<point key="canvasLocation" x="52" y="374.66266866566718"/>
</scene>
</scenes>
<resources>
<image name="icon" width="512" height="512"/>
</resources>
</document>
18 changes: 17 additions & 1 deletion Keep Standing/HealthManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import HealthKit

typealias HealthManagerHandler = (_ success: Bool, _ error: Error?) ->Void
typealias HealthManagerHandler = (_ success: Bool, _ error: Error?) -> Void
typealias HealthManagerSampleHandler = (_ sample: HKSample?, _ error: Error?) -> Void


Expand Down Expand Up @@ -123,6 +123,22 @@ final class HealthManager {
self.healthStore.execute(query)
}

//
// Report calories to HealthKit
//
func report(calories: Double, date: Date, completion: @escaping HealthManagerHandler) {
let caloriesType = HKQuantityType.quantityType(forIdentifier: .activeEnergyBurned)!

let caloriesQuantity = HKQuantity(unit: HKUnit.calorie(), doubleValue: calories)

let caloriesSample = HKQuantitySample(type: caloriesType, quantity: caloriesQuantity,
start: date, end: date)

self.healthStore.save(caloriesSample) { success, error in
completion(success, error)
}
}

//
// Gets the weight of the user using the getData helper function.
//
Expand Down
2 changes: 1 addition & 1 deletion Keep Standing/IntroVC.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
  //
// IntroVC.swift
// Keep Standing
//
Expand Down
Loading

0 comments on commit b42ca80

Please sign in to comment.