Skip to content

Commit 40fb49b

Browse files
Steve TreaseSteve Trease
authored andcommitted
Added display of yesterday's steps to iOS app
1 parent c28ee8a commit 40fb49b

File tree

9 files changed

+67
-17
lines changed

9 files changed

+67
-17
lines changed

build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
598
1+
605

iOS Steps Today/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>1.0</string>
2121
<key>CFBundleVersion</key>
22-
<string>598</string>
22+
<string>605</string>
2323
<key>NSExtension</key>
2424
<dict>
2525
<key>NSExtensionMainStoryboard</key>

iOS Steps Watch Extension/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>1.0</string>
2121
<key>CFBundleVersion</key>
22-
<string>598</string>
22+
<string>605</string>
2323
<key>NSExtension</key>
2424
<dict>
2525
<key>NSExtensionAttributes</key>

iOS Steps Watch Extension/InterfaceController.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ class InterfaceController: WKInterfaceController {
1616

1717
@IBOutlet var stepsLabel: WKInterfaceLabel!
1818
@IBOutlet var averageLabel: WKInterfaceLabel!
19+
@IBOutlet var yesterdayLabel: WKInterfaceLabel!
1920

2021

2122
var stepsToday: Double = 0.0
23+
var stepsYesterday: Double = 0.0
2224
var sevenDayStepAverage: Double = 100000.0
2325
var sevenDayStepAverageLastUpdated: Date = Date.distantPast
2426

@@ -111,6 +113,17 @@ class InterfaceController: WKInterfaceController {
111113
}
112114
}
113115
})
116+
117+
getYesterdayStepCount (completion: { (steps) in
118+
if steps != -1.0 {
119+
self.stepsYesterday = steps!
120+
OperationQueue.main.addOperation {
121+
let numberString = self.numberFormatter.string(from: steps! as NSNumber)
122+
self.yesterdayLabel.setText(numberString!)
123+
}
124+
}
125+
})
126+
114127
}
115128
}
116129

@@ -143,6 +156,34 @@ class InterfaceController: WKInterfaceController {
143156
}
144157

145158

159+
func getYesterdayStepCount(completion:@escaping (Double?)->())
160+
{
161+
// Define the sample type
162+
let type = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)
163+
164+
let cal = Calendar.current
165+
let endDate = cal.startOfDay(for: Date())
166+
let startDate = cal.date(byAdding: .day, value: -1, to: endDate)
167+
168+
// Set the predicate
169+
let predicate = HKQuery.predicateForSamples(withStart: startDate, end: endDate, options: [])
170+
171+
let query = HKStatisticsQuery(quantityType: type!, quantitySamplePredicate: predicate, options: .cumulativeSum) { query, results, error in
172+
let quantity = results?.sumQuantity()
173+
let unit = HKUnit.count()
174+
let steps = quantity?.doubleValue(for: unit)
175+
176+
if steps != nil {
177+
completion(steps)
178+
} else {
179+
print("getTodayStepCount: results are nil - returning nil steps")
180+
completion(-1.0)
181+
}
182+
}
183+
healthStore.execute(query)
184+
}
185+
186+
146187
func getSevenDayStepAverage(completion:@escaping (Double?)->())
147188
{
148189
// Define the sample type

iOS Steps Watch/Base.lproj/Interface.storyboard

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="13122.17" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="AgC-eL-Hgc">
2+
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="13156.6" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="AgC-eL-Hgc">
33
<device id="watch42" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
66
<dependencies>
77
<deployment identifier="watchOS"/>
8-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.14"/>
9-
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="13034"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13137.5"/>
9+
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="13040"/>
1010
</dependencies>
1111
<scenes>
1212
<!--Steps-->
1313
<scene sceneID="aou-V4-d1y">
1414
<objects>
1515
<controller identifier="Steps" title="Steps" id="AgC-eL-Hgc" customClass="InterfaceController" customModule="iOS_Steps_Watch" customModuleProvider="target">
1616
<items>
17-
<label width="1" height="0.5" alignment="center" text="-" textAlignment="center" minimumScaleFactor="0.59999999999999998" id="jRp-pr-6vw">
18-
<fontDescription key="font" type="system" pointSize="48"/>
19-
</label>
20-
<label width="1" height="0.5" alignment="center" verticalAlignment="bottom" text="-" textAlignment="center" id="W3B-9J-eM0">
21-
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
22-
<fontDescription key="font" type="system" pointSize="24"/>
23-
</label>
17+
<group width="1" height="1" alignment="left" layout="vertical" id="ncs-BT-a4C">
18+
<items>
19+
<label alignment="center" text="-" textAlignment="center" minimumScaleFactor="0.59999999999999998" id="jRp-pr-6vw">
20+
<fontDescription key="font" type="system" pointSize="48"/>
21+
</label>
22+
<label alignment="center" verticalAlignment="center" text="-" textAlignment="center" id="oby-VJ-Rg4">
23+
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
24+
<fontDescription key="font" type="system" pointSize="16"/>
25+
</label>
26+
<label alignment="center" verticalAlignment="bottom" text="-" textAlignment="center" id="W3B-9J-eM0">
27+
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
28+
<fontDescription key="font" type="system" pointSize="24"/>
29+
</label>
30+
</items>
31+
</group>
2432
</items>
2533
<connections>
2634
<outlet property="averageLabel" destination="W3B-9J-eM0" id="Zjg-gc-mob"/>
2735
<outlet property="stepsLabel" destination="jRp-pr-6vw" id="gxc-mO-hfM"/>
36+
<outlet property="yesterdayLabel" destination="oby-VJ-Rg4" id="UkM-ET-ENH"/>
2837
</connections>
2938
</controller>
3039
</objects>

iOS Steps Watch/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>1.0</string>
2121
<key>CFBundleVersion</key>
22-
<string>598</string>
22+
<string>605</string>
2323
<key>UIBackgroundModes</key>
2424
<array/>
2525
<key>UISupportedInterfaceOrientations</key>

iOS Steps/Base.lproj/LaunchScreen.storyboard

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
2222
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2323
<subviews>
24-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Build: 598 (180dc54)" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="yhA-lX-4Of" userLabel="APP_VERSION">
24+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Build: 605 (c28ee8a)" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="yhA-lX-4Of" userLabel="APP_VERSION">
2525
<rect key="frame" x="132.5" y="527" width="55.5" height="21"/>
2626
<fontDescription key="fontDescription" type="system" pointSize="17"/>
2727
<nil key="textColor"/>

iOS Steps/Base.lproj/LaunchScreen.storyboardbak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
2222
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2323
<subviews>
24-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Build: 597 (180dc54)" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="yhA-lX-4Of" userLabel="APP_VERSION">
24+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Build: 604 (c28ee8a)" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="yhA-lX-4Of" userLabel="APP_VERSION">
2525
<rect key="frame" x="132.5" y="527" width="55.5" height="21"/>
2626
<fontDescription key="fontDescription" type="system" pointSize="17"/>
2727
<nil key="textColor"/>

iOS Steps/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</dict>
2929
</array>
3030
<key>CFBundleVersion</key>
31-
<string>598</string>
31+
<string>605</string>
3232
<key>LSRequiresIPhoneOS</key>
3333
<true/>
3434
<key>NSHealthShareUsageDescription</key>

0 commit comments

Comments
 (0)