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="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"/>
|
||||||
|
@ -32,6 +32,7 @@ class ViewController: UIViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func updateAuthorizedLabel() {
|
fileprivate func updateAuthorizedLabel() {
|
||||||
|
DispatchQueue.main.async {
|
||||||
if self.client.isAuthorized() {
|
if self.client.isAuthorized() {
|
||||||
self.loggedIn.text = "Logged In"
|
self.loggedIn.text = "Logged In"
|
||||||
//self.loginButton.currentTitle = "Log Out"
|
//self.loginButton.currentTitle = "Log Out"
|
||||||
@ -40,6 +41,7 @@ class ViewController: UIViewController {
|
|||||||
//self.loginButton.currentTitle = "Log In"
|
//self.loginButton.currentTitle = "Log In"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Ensure that the client is authorized and then continue
|
/// Ensure that the client is authorized and then continue
|
||||||
fileprivate func ensureAuthorized(callback: @escaping (Bool) -> Void) {
|
fileprivate func ensureAuthorized(callback: @escaping (Bool) -> Void) {
|
||||||
@ -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"
|
||||||
|
Loading…
Reference in New Issue
Block a user