Update the output text to display some friendly error messages
This commit is contained in:
parent
4a8c65d751
commit
bc5e9e9d2b
@ -32,8 +32,8 @@
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="IdY-jU-MBP">
|
||||
<rect key="frame" x="16" y="152" width="343" height="305"/>
|
||||
<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="87"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||
|
@ -32,6 +32,7 @@ class ViewController: UIViewController {
|
||||
}
|
||||
|
||||
fileprivate func updateAuthorizedLabel() {
|
||||
DispatchQueue.main.async {
|
||||
if self.client.isAuthorized() {
|
||||
self.loggedIn.text = "Logged In"
|
||||
//self.loginButton.currentTitle = "Log Out"
|
||||
@ -40,6 +41,7 @@ class ViewController: UIViewController {
|
||||
//self.loginButton.currentTitle = "Log In"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure that the client is authorized and then continue
|
||||
fileprivate func ensureAuthorized(callback: @escaping (Bool) -> Void) {
|
||||
@ -62,12 +64,9 @@ class ViewController: UIViewController {
|
||||
NSLog("Authorized for scope: \(scope). Requesting HealthKit access")
|
||||
HealthKitHelper.authorizeHealthKit() {
|
||||
result, error in
|
||||
// TODO: Do something with the result and error
|
||||
if error != nil {
|
||||
callback(false)
|
||||
} else {
|
||||
callback(true)
|
||||
}
|
||||
// TODO: Enforce that access was provided or display an error
|
||||
NSLog("Error authing HealthKit: \(error.debugDescription)")
|
||||
callback(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -76,6 +75,8 @@ class ViewController: UIViewController {
|
||||
self.updateAuthorizedLabel()
|
||||
if authSuccess {
|
||||
self.syncWeights()
|
||||
} else {
|
||||
self.outputText.text = "Error connecting to Fitbit or authorizing"
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,7 +95,7 @@ class ViewController: UIViewController {
|
||||
|
||||
if let fbWeights = 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})
|
||||
}
|
||||
self.outputText.text = "Health data is synced"
|
||||
|
Loading…
Reference in New Issue
Block a user