Update the output text to display some friendly error messages

This commit is contained in:
IamTheFij 2018-01-19 21:40:05 -08:00
parent 4a8c65d751
commit bc5e9e9d2b
2 changed files with 16 additions and 15 deletions

View File

@ -32,8 +32,8 @@
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="IdY-jU-MBP"> <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" textAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="IdY-jU-MBP">
<rect key="frame" x="16" y="152" width="343" height="305"/> <rect key="frame" x="16" y="152" width="343" height="87"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/> <fontDescription key="fontDescription" type="system" pointSize="14"/>

View File

@ -32,12 +32,14 @@ class ViewController: UIViewController {
} }
fileprivate func updateAuthorizedLabel() { fileprivate func updateAuthorizedLabel() {
if self.client.isAuthorized() { DispatchQueue.main.async {
self.loggedIn.text = "Logged In" if self.client.isAuthorized() {
//self.loginButton.currentTitle = "Log Out" self.loggedIn.text = "Logged In"
} else { //self.loginButton.currentTitle = "Log Out"
self.loggedIn.text = "Not Logged In" } else {
//self.loginButton.currentTitle = "Log In" self.loggedIn.text = "Not Logged In"
//self.loginButton.currentTitle = "Log In"
}
} }
} }
@ -62,12 +64,9 @@ class ViewController: UIViewController {
NSLog("Authorized for scope: \(scope). Requesting HealthKit access") NSLog("Authorized for scope: \(scope). Requesting HealthKit access")
HealthKitHelper.authorizeHealthKit() { HealthKitHelper.authorizeHealthKit() {
result, error in result, error in
// TODO: Do something with the result and error // TODO: Enforce that access was provided or display an error
if error != nil { NSLog("Error authing HealthKit: \(error.debugDescription)")
callback(false) callback(result)
} else {
callback(true)
}
} }
} }
} }
@ -76,6 +75,8 @@ class ViewController: UIViewController {
self.updateAuthorizedLabel() self.updateAuthorizedLabel()
if authSuccess { if authSuccess {
self.syncWeights() self.syncWeights()
} else {
self.outputText.text = "Error connecting to Fitbit or authorizing"
} }
} }
@ -94,7 +95,7 @@ class ViewController: UIViewController {
if let fbWeights = fbWeights { if let fbWeights = fbWeights {
for fbWeight in fbWeights { for fbWeight in fbWeights {
NSLog("Got Weight: \(fbWeight.logId): \(fbWeight.date) \(fbWeight.weight)") NSLog("Got Weight with ID: \(fbWeight.logId)")
HealthKitHelper.maybeSaveSample(fbWeight, callback: {_,_ in}) HealthKitHelper.maybeSaveSample(fbWeight, callback: {_,_ in})
} }
self.outputText.text = "Health data is synced" self.outputText.text = "Health data is synced"