From b380b283a8fec6302867e4b9132330a3e39f62d1 Mon Sep 17 00:00:00 2001 From: diggabyte Date: Wed, 22 Aug 2018 15:10:41 -0600 Subject: [PATCH] Added success haptic to WatchApp carb, bolus sends --- .../Controllers/AddCarbsInterfaceController.swift | 1 + .../Controllers/BolusInterfaceController.swift | 13 +++++++++---- WatchApp Extension/Extensions/WCSession.swift | 5 +++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/WatchApp Extension/Controllers/AddCarbsInterfaceController.swift b/WatchApp Extension/Controllers/AddCarbsInterfaceController.swift index e21d0fe8ac..6ec6ff873d 100644 --- a/WatchApp Extension/Controllers/AddCarbsInterfaceController.swift +++ b/WatchApp Extension/Controllers/AddCarbsInterfaceController.swift @@ -163,6 +163,7 @@ final class AddCarbsInterfaceController: WKInterfaceController, IdentifiableClas do { try WCSession.default.sendCarbEntryMessage(entry, replyHandler: { (suggestion) in + WKInterfaceDevice.current().play(.success) DispatchQueue.main.async { WKExtension.shared().rootInterfaceController?.presentController(withName: BolusInterfaceController.className, context: suggestion) } diff --git a/WatchApp Extension/Controllers/BolusInterfaceController.swift b/WatchApp Extension/Controllers/BolusInterfaceController.swift index ff2bf99613..a9b8bd9537 100644 --- a/WatchApp Extension/Controllers/BolusInterfaceController.swift +++ b/WatchApp Extension/Controllers/BolusInterfaceController.swift @@ -135,11 +135,16 @@ final class BolusInterfaceController: WKInterfaceController, IdentifiableClass { let bolus = SetBolusUserInfo(value: bolusValue, startDate: Date()) do { - try WCSession.default.sendBolusMessage(bolus) { (error) in - DispatchQueue.main.async { - ExtensionDelegate.shared().present(error) + try WCSession.default.sendBolusMessage(bolus, + replyHandler: { _ in + WKInterfaceDevice.current().play(.success) + }, + errorHandler: { (error) in + DispatchQueue.main.async { + ExtensionDelegate.shared().present(error) + } } - } + ) } catch { presentAlert( withTitle: NSLocalizedString("Bolus Failed", comment: "The title of the alert controller displayed after a bolus attempt fails"), diff --git a/WatchApp Extension/Extensions/WCSession.swift b/WatchApp Extension/Extensions/WCSession.swift index 11c9114131..784021ea2c 100644 --- a/WatchApp Extension/Extensions/WCSession.swift +++ b/WatchApp Extension/Extensions/WCSession.swift @@ -40,7 +40,8 @@ extension WCSession { ) } - func sendBolusMessage(_ userInfo: SetBolusUserInfo, errorHandler: @escaping (Error) -> Void) throws { + func sendBolusMessage(_ userInfo: SetBolusUserInfo, replyHandler: @escaping ([String: Any]) -> Void, + errorHandler: @escaping (Error) -> Void) throws { guard activationState == .activated else { throw MessageError.activationError } @@ -50,7 +51,7 @@ extension WCSession { } sendMessage(userInfo.rawValue, - replyHandler: { reply in }, + replyHandler: replyHandler, errorHandler: errorHandler ) }