From a5bc15a4ab55aac397d27a39c87d5a5ee1b52311 Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Mon, 1 Oct 2018 14:05:15 -0500 Subject: [PATCH 1/7] Fix issue report crash, and track pump frequency. (#821) --- Cartfile | 4 ++-- Cartfile.resolved | 4 ++-- DoseMathTests/Info.plist | 2 +- Loop Status Extension/Info.plist | 2 +- Loop.xcodeproj/project.pbxproj | 12 ++++++------ Loop/Info.plist | 2 +- LoopTests/Info.plist | 2 +- LoopUI/Info.plist | 2 +- WatchApp Extension/Info.plist | 2 +- WatchApp/Info.plist | 2 +- 10 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Cartfile b/Cartfile index 17e1ca9dc5..55c17b5336 100644 --- a/Cartfile +++ b/Cartfile @@ -1,7 +1,7 @@ -github "LoopKit/LoopKit" == 2.1.3 +github "LoopKit/LoopKit" == 2.1.5 github "LoopKit/CGMBLEKit" == 2.1.1 github "i-schuetz/SwiftCharts" == 0.6.2 github "mddub/dexcom-share-client-swift" == 0.4.1 github "mddub/G4ShareSpy" == 0.3.3 -github "ps2/rileylink_ios" == 2.0.6 +github "ps2/rileylink_ios" == 2.0.7 github "LoopKit/Amplitude-iOS" "decreepify" diff --git a/Cartfile.resolved b/Cartfile.resolved index 0071486027..21812dd5c7 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,7 +1,7 @@ github "LoopKit/Amplitude-iOS" "2137d5fd44bf630ed33e1e72d7af6d8f8612f270" github "LoopKit/CGMBLEKit" "v2.1.1" -github "LoopKit/LoopKit" "v2.1.3" +github "LoopKit/LoopKit" "v2.1.5" github "i-schuetz/SwiftCharts" "0.6.2" github "mddub/G4ShareSpy" "v0.3.3" github "mddub/dexcom-share-client-swift" "v0.4.1" -github "ps2/rileylink_ios" "v2.0.6" +github "ps2/rileylink_ios" "v2.0.7" diff --git a/DoseMathTests/Info.plist b/DoseMathTests/Info.plist index 4507c55102..d4152c96a0 100644 --- a/DoseMathTests/Info.plist +++ b/DoseMathTests/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.9.2 + 1.9.3 CFBundleSignature ???? CFBundleVersion diff --git a/Loop Status Extension/Info.plist b/Loop Status Extension/Info.plist index 0e43389ef6..613009f16d 100644 --- a/Loop Status Extension/Info.plist +++ b/Loop Status Extension/Info.plist @@ -19,7 +19,7 @@ CFBundlePackageType XPC! CFBundleShortVersionString - 1.9.2 + 1.9.3 CFBundleVersion $(CURRENT_PROJECT_VERSION) AppGroupIdentifier diff --git a/Loop.xcodeproj/project.pbxproj b/Loop.xcodeproj/project.pbxproj index 3365a8388a..4f7d8df250 100644 --- a/Loop.xcodeproj/project.pbxproj +++ b/Loop.xcodeproj/project.pbxproj @@ -2442,7 +2442,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Developer: loudnate@gmail.com (XZN842LDLT)"; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 53; + CURRENT_PROJECT_VERSION = 54; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -2514,7 +2514,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Developer: loudnate@gmail.com (XZN842LDLT)"; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 53; + CURRENT_PROJECT_VERSION = 54; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -2765,11 +2765,11 @@ CLANG_WARN_SUSPICIOUS_MOVES = YES; CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; - CURRENT_PROJECT_VERSION = 53; + CURRENT_PROJECT_VERSION = 54; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 53; + DYLIB_CURRENT_VERSION = 54; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = LoopUI/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -2792,11 +2792,11 @@ CLANG_WARN_SUSPICIOUS_MOVES = YES; CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; - CURRENT_PROJECT_VERSION = 53; + CURRENT_PROJECT_VERSION = 54; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 53; + DYLIB_CURRENT_VERSION = 54; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = LoopUI/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; diff --git a/Loop/Info.plist b/Loop/Info.plist index e5951d83e9..51de45c8dc 100644 --- a/Loop/Info.plist +++ b/Loop/Info.plist @@ -19,7 +19,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.9.2 + 1.9.3 CFBundleSignature ???? CFBundleURLTypes diff --git a/LoopTests/Info.plist b/LoopTests/Info.plist index 4507c55102..d4152c96a0 100644 --- a/LoopTests/Info.plist +++ b/LoopTests/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.9.2 + 1.9.3 CFBundleSignature ???? CFBundleVersion diff --git a/LoopUI/Info.plist b/LoopUI/Info.plist index ead3c07674..8ac931c440 100644 --- a/LoopUI/Info.plist +++ b/LoopUI/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.9.2 + 1.9.3 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass diff --git a/WatchApp Extension/Info.plist b/WatchApp Extension/Info.plist index 44c9ce1e78..72ad48bfe9 100644 --- a/WatchApp Extension/Info.plist +++ b/WatchApp Extension/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType XPC! CFBundleShortVersionString - 1.9.2 + 1.9.3 CFBundleSignature ???? CFBundleVersion diff --git a/WatchApp/Info.plist b/WatchApp/Info.plist index 6817e1d304..750ca80dd6 100644 --- a/WatchApp/Info.plist +++ b/WatchApp/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.9.2 + 1.9.3 CFBundleSignature ???? CFBundleVersion From deea4551f01f404d4edfb108dcfbc0d49111e760 Mon Sep 17 00:00:00 2001 From: apabari Date: Mon, 15 Oct 2018 13:09:12 -0400 Subject: [PATCH 2/7] Apple Watch Series 4 Complications Enhancements for Apple Watch Series 4 --> .graphicCorner (Outer Text: Glucose and Trend, Inner Text: time) --> .graphicCircular (Full Ring with Current Glucose in Center, Trend Arrow Below) --- CLKComplicationTemplate.swift | 133 +++++++++++++++++++++++++++++ ComplicationController.swift | 154 ++++++++++++++++++++++++++++++++++ Info.plist | 56 +++++++++++++ 3 files changed, 343 insertions(+) create mode 100644 CLKComplicationTemplate.swift create mode 100644 ComplicationController.swift create mode 100644 Info.plist diff --git a/CLKComplicationTemplate.swift b/CLKComplicationTemplate.swift new file mode 100644 index 0000000000..758a643f2d --- /dev/null +++ b/CLKComplicationTemplate.swift @@ -0,0 +1,133 @@ +// +// CLKComplicationTemplate.swift +// Naterade +// +// Created by Nathan Racklyeft on 11/26/15. +// Copyright © 2015 Nathan Racklyeft. All rights reserved. +// + +import ClockKit +import HealthKit +import LoopKit +import Foundation + + +extension CLKComplicationTemplate { + + static func templateForFamily(_ family: CLKComplicationFamily, from context: WatchContext) -> CLKComplicationTemplate? { + guard let glucose = context.glucose, let unit = context.preferredGlucoseUnit else { + return nil + } + + return templateForFamily(family, glucose: glucose, unit: unit, date: context.glucoseDate, trend: context.glucoseTrend, eventualGlucose: context.eventualGlucose) + } + + static func templateForFamily(_ family: CLKComplicationFamily, glucose: HKQuantity, unit: HKUnit, date: Date?, trend: GlucoseTrend?, eventualGlucose: HKQuantity?) -> CLKComplicationTemplate? { + + let formatter = NumberFormatter.glucoseFormatter(for: unit) + + guard let glucoseString = formatter.string(from: glucose.doubleValue(for: unit)), + let date = date else + { + return nil + } + + let glucoseAndTrend = "\(glucoseString)\(trend?.symbol ?? " ")" + var accessibilityStrings = [glucoseString] + + if let trend = trend { + accessibilityStrings.append(trend.localizedDescription) + } + + let glucoseAndTrendText = CLKSimpleTextProvider(text: glucoseAndTrend, shortText: glucoseString, accessibilityLabel: accessibilityStrings.joined(separator: ", ")) + let timeText = CLKRelativeDateTextProvider(date: date, style: .natural, units: .minute) + + let timeFormatter = DateFormatter() + timeFormatter.dateStyle = .none + timeFormatter.timeStyle = .short + + + switch family { + case .graphicCorner: + // *************************************** + // ** Apple Watch Series 4 Complication ** + // *************************************** + // Corner Text + // Outer Text: Current Glucose and Trend + // Inner Text: timeText + + if #available(watchOSApplicationExtension 5.0, *) { + let cornerTemplate = CLKComplicationTemplateGraphicCornerStackText() + cornerTemplate.outerTextProvider = glucoseAndTrendText + cornerTemplate.outerTextProvider.tintColor = .green + cornerTemplate.innerTextProvider = timeText + return cornerTemplate + } else { + // Fallback on earlier versions + return nil + } + case .graphicCircular: + // *************************************** + // ** Apple Watch Series 4 Complication ** + // *************************************** + // Circular Gauge + // Full Ring + // Current Glucose in Center, Trend Arrow Below + // * future enhancement - update gauge colors to reflect loop status, or time in range for the day + if #available(watchOSApplicationExtension 5.0, *) { + let circularTemplate = CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText() + circularTemplate.gaugeProvider = CLKSimpleGaugeProvider(style: .fill, gaugeColor: .green, fillFraction: 1) + circularTemplate.centerTextProvider = CLKSimpleTextProvider(text: glucoseString) + circularTemplate.bottomTextProvider = CLKSimpleTextProvider(text: (trend?.symbol ?? " ")) + return circularTemplate + } else { + // Fallback on earlier versions + return nil + } + case .graphicRectangular, .graphicBezel: + return nil + case .modularSmall: + let template = CLKComplicationTemplateModularSmallStackText() + template.line1TextProvider = glucoseAndTrendText + template.line2TextProvider = timeText + return template + case .modularLarge: + let template = CLKComplicationTemplateModularLargeTallBody() + template.bodyTextProvider = glucoseAndTrendText + template.headerTextProvider = timeText + return template + case .circularSmall: + let template = CLKComplicationTemplateCircularSmallSimpleText() + template.textProvider = CLKSimpleTextProvider(text: glucoseString) + return template + case .extraLarge: + let template = CLKComplicationTemplateExtraLargeStackText() + template.line1TextProvider = glucoseAndTrendText + template.line2TextProvider = timeText + return template + case .utilitarianSmall, .utilitarianSmallFlat: + let template = CLKComplicationTemplateUtilitarianSmallFlat() + template.textProvider = CLKSimpleTextProvider(text: glucoseString) + + return template + case .utilitarianLarge: + var eventualGlucoseText = "" + if let eventualGlucose = eventualGlucose, + let eventualGlucoseString = formatter.string(from: eventualGlucose.doubleValue(for: unit)) + { + eventualGlucoseText = eventualGlucoseString + } + + let template = CLKComplicationTemplateUtilitarianLargeFlat() + let format = NSLocalizedString("UtilitarianLargeFlat", tableName: "ckcomplication", comment: "Utilitarian large flat format string (1: Glucose & Trend symbol) (2: Eventual Glucose) (3: Time)") + + template.textProvider = CLKSimpleTextProvider(text: String(format: format, arguments: [ + glucoseAndTrend, + eventualGlucoseText, + timeFormatter.string(from: date) + ] + )) + return template + } + } +} diff --git a/ComplicationController.swift b/ComplicationController.swift new file mode 100644 index 0000000000..d632954571 --- /dev/null +++ b/ComplicationController.swift @@ -0,0 +1,154 @@ +// +// ComplicationController.swift +// WatchApp Extension +// +// Created by Nathan Racklyeft on 8/29/15. +// Copyright © 2015 Nathan Racklyeft. All rights reserved. +// + +import ClockKit +import WatchKit + + +final class ComplicationController: NSObject, CLKComplicationDataSource { + + // MARK: - Timeline Configuration + + func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) { + handler([.backward]) + } + + func getTimelineStartDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) { + if let date = ExtensionDelegate.shared().lastContext?.glucoseDate { + handler(date) + } else { + handler(nil) + } + } + + func getTimelineEndDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) { + if let date = ExtensionDelegate.shared().lastContext?.glucoseDate { + handler(date) + } else { + handler(nil) + } + } + + func getPrivacyBehavior(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationPrivacyBehavior) -> Void) { + handler(.hideOnLockScreen) + } + + // MARK: - Timeline Population + + private lazy var formatter = NumberFormatter() + + func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: (@escaping (CLKComplicationTimelineEntry?) -> Void)) { + let entry: CLKComplicationTimelineEntry? + + if let context = ExtensionDelegate.shared().lastContext, + let glucoseDate = context.glucoseDate, + glucoseDate.timeIntervalSinceNow.minutes >= -15, + let template = CLKComplicationTemplate.templateForFamily(complication.family, from: context) + { + template.tintColor = UIColor.tintColor + entry = CLKComplicationTimelineEntry(date: glucoseDate, complicationTemplate: template) + } else { + entry = nil + } + + handler(entry) + } + + func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int, withHandler handler: (@escaping ([CLKComplicationTimelineEntry]?) -> Void)) { + // Call the handler with the timeline entries prior to the given date + handler(nil) + } + + func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int, withHandler handler: (@escaping ([CLKComplicationTimelineEntry]?) -> Void)) { + // Call the handler with the timeline entries after to the given date + let entries: [CLKComplicationTimelineEntry]? + + if let context = ExtensionDelegate.shared().lastContext, + let glucoseDate = context.glucoseDate, + glucoseDate.timeIntervalSince(date) > 0, + let template = CLKComplicationTemplate.templateForFamily(complication.family, from: context) + { + template.tintColor = UIColor.tintColor + entries = [CLKComplicationTimelineEntry(date: glucoseDate, complicationTemplate: template)] + } else { + entries = nil + } + + handler(entries) + } + + // MARK: - Placeholder Templates + + func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) { + + let template: CLKComplicationTemplate? + + let glucoseText = CLKSimpleTextProvider.localizableTextProvider(withStringsFileTextKey: "120↘︎", shortTextKey: "120") + let timeText = CLKRelativeDateTextProvider(date: Date(), style: .natural, units: .minute) + + switch complication.family { + + case .graphicCorner: + if #available(watchOSApplicationExtension 5.0, *) { + let cornerTemplate = CLKComplicationTemplateGraphicCornerStackText() + cornerTemplate.outerTextProvider = glucoseText + cornerTemplate.innerTextProvider = timeText + cornerTemplate.outerTextProvider.tintColor = .green + template = cornerTemplate + } else { + // Fallback on earlier versions + template = nil + } + case .graphicCircular: + if #available(watchOSApplicationExtension 5.0, *) { + let circularTemplate = CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText() + circularTemplate.gaugeProvider = CLKSimpleGaugeProvider(style: .fill, gaugeColor: .green, fillFraction: 1) + circularTemplate.centerTextProvider = CLKSimpleTextProvider(text: "120") + circularTemplate.bottomTextProvider = CLKSimpleTextProvider(text: "↘︎") + template = circularTemplate + } else { + // Fallback on earlier versions + template = nil + } + case .graphicRectangular, .graphicBezel: + template = nil + case .modularSmall: + let modularSmall = CLKComplicationTemplateModularSmallStackText() + modularSmall.line1TextProvider = glucoseText + modularSmall.line2TextProvider = timeText + template = modularSmall + case .modularLarge: + let modularSmall = CLKComplicationTemplateModularLargeTallBody() + modularSmall.bodyTextProvider = glucoseText + modularSmall.headerTextProvider = timeText + template = modularSmall + case .circularSmall: + let circularSmall = CLKComplicationTemplateCircularSmallSimpleText() + circularSmall.textProvider = glucoseText + template = circularSmall + case .extraLarge: + let extraLarge = CLKComplicationTemplateExtraLargeStackText() + extraLarge.line1TextProvider = glucoseText + extraLarge.line2TextProvider = timeText + template = extraLarge + case .utilitarianSmall, .utilitarianSmallFlat: + let utilitarianSmallFlat = CLKComplicationTemplateUtilitarianSmallFlat() + utilitarianSmallFlat.textProvider = glucoseText + template = utilitarianSmallFlat + case .utilitarianLarge: + let utilitarianLarge = CLKComplicationTemplateUtilitarianLargeFlat() + let eventualGlucoseText = CLKSimpleTextProvider.localizableTextProvider(withStringsFileTextKey: "75") + utilitarianLarge.textProvider = CLKSimpleTextProvider.localizableTextProvider(withStringsFileFormatKey: "UtilitarianLargeFlat", textProviders: [glucoseText, eventualGlucoseText, CLKTimeTextProvider(date: Date())]) + template = utilitarianLarge + } + + template?.tintColor = UIColor.tintColor + handler(template) + + } +} diff --git a/Info.plist b/Info.plist new file mode 100644 index 0000000000..d9ff34f6f8 --- /dev/null +++ b/Info.plist @@ -0,0 +1,56 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + WatchApp Extension + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + XPC! + CFBundleShortVersionString + 1.9.3 + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + CLKComplicationPrincipalClass + $(PRODUCT_MODULE_NAME).ComplicationController + CLKComplicationSupportedFamilies + + CLKComplicationFamilyCircularSmall + CLKComplicationFamilyExtraLarge + CLKComplicationFamilyGraphicBezel + CLKComplicationFamilyGraphicCircular + CLKComplicationFamilyGraphicCorner + CLKComplicationFamilyGraphicRectangular + CLKComplicationFamilyModularLarge + CLKComplicationFamilyModularSmall + CLKComplicationFamilyUtilitarianLarge + CLKComplicationFamilyUtilitarianSmall + CLKComplicationFamilyUtilitarianSmallFlat + + NSExtension + + NSExtensionAttributes + + WKAppBundleIdentifier + $(MAIN_APP_BUNDLE_IDENTIFIER).LoopWatch + + NSExtensionPointIdentifier + com.apple.watchkit + + RemoteInterfacePrincipalClass + $(PRODUCT_MODULE_NAME).StatusInterfaceController + WKExtensionDelegateClassName + $(PRODUCT_MODULE_NAME).ExtensionDelegate + + From e2c3104a4ad08a1c56cde5cdea6cadd4241f3aab Mon Sep 17 00:00:00 2001 From: apabari Date: Mon, 15 Oct 2018 13:12:59 -0400 Subject: [PATCH 3/7] Delete ComplicationController.swift --- ComplicationController.swift | 154 ----------------------------------- 1 file changed, 154 deletions(-) delete mode 100644 ComplicationController.swift diff --git a/ComplicationController.swift b/ComplicationController.swift deleted file mode 100644 index d632954571..0000000000 --- a/ComplicationController.swift +++ /dev/null @@ -1,154 +0,0 @@ -// -// ComplicationController.swift -// WatchApp Extension -// -// Created by Nathan Racklyeft on 8/29/15. -// Copyright © 2015 Nathan Racklyeft. All rights reserved. -// - -import ClockKit -import WatchKit - - -final class ComplicationController: NSObject, CLKComplicationDataSource { - - // MARK: - Timeline Configuration - - func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) { - handler([.backward]) - } - - func getTimelineStartDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) { - if let date = ExtensionDelegate.shared().lastContext?.glucoseDate { - handler(date) - } else { - handler(nil) - } - } - - func getTimelineEndDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) { - if let date = ExtensionDelegate.shared().lastContext?.glucoseDate { - handler(date) - } else { - handler(nil) - } - } - - func getPrivacyBehavior(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationPrivacyBehavior) -> Void) { - handler(.hideOnLockScreen) - } - - // MARK: - Timeline Population - - private lazy var formatter = NumberFormatter() - - func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: (@escaping (CLKComplicationTimelineEntry?) -> Void)) { - let entry: CLKComplicationTimelineEntry? - - if let context = ExtensionDelegate.shared().lastContext, - let glucoseDate = context.glucoseDate, - glucoseDate.timeIntervalSinceNow.minutes >= -15, - let template = CLKComplicationTemplate.templateForFamily(complication.family, from: context) - { - template.tintColor = UIColor.tintColor - entry = CLKComplicationTimelineEntry(date: glucoseDate, complicationTemplate: template) - } else { - entry = nil - } - - handler(entry) - } - - func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int, withHandler handler: (@escaping ([CLKComplicationTimelineEntry]?) -> Void)) { - // Call the handler with the timeline entries prior to the given date - handler(nil) - } - - func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int, withHandler handler: (@escaping ([CLKComplicationTimelineEntry]?) -> Void)) { - // Call the handler with the timeline entries after to the given date - let entries: [CLKComplicationTimelineEntry]? - - if let context = ExtensionDelegate.shared().lastContext, - let glucoseDate = context.glucoseDate, - glucoseDate.timeIntervalSince(date) > 0, - let template = CLKComplicationTemplate.templateForFamily(complication.family, from: context) - { - template.tintColor = UIColor.tintColor - entries = [CLKComplicationTimelineEntry(date: glucoseDate, complicationTemplate: template)] - } else { - entries = nil - } - - handler(entries) - } - - // MARK: - Placeholder Templates - - func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) { - - let template: CLKComplicationTemplate? - - let glucoseText = CLKSimpleTextProvider.localizableTextProvider(withStringsFileTextKey: "120↘︎", shortTextKey: "120") - let timeText = CLKRelativeDateTextProvider(date: Date(), style: .natural, units: .minute) - - switch complication.family { - - case .graphicCorner: - if #available(watchOSApplicationExtension 5.0, *) { - let cornerTemplate = CLKComplicationTemplateGraphicCornerStackText() - cornerTemplate.outerTextProvider = glucoseText - cornerTemplate.innerTextProvider = timeText - cornerTemplate.outerTextProvider.tintColor = .green - template = cornerTemplate - } else { - // Fallback on earlier versions - template = nil - } - case .graphicCircular: - if #available(watchOSApplicationExtension 5.0, *) { - let circularTemplate = CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText() - circularTemplate.gaugeProvider = CLKSimpleGaugeProvider(style: .fill, gaugeColor: .green, fillFraction: 1) - circularTemplate.centerTextProvider = CLKSimpleTextProvider(text: "120") - circularTemplate.bottomTextProvider = CLKSimpleTextProvider(text: "↘︎") - template = circularTemplate - } else { - // Fallback on earlier versions - template = nil - } - case .graphicRectangular, .graphicBezel: - template = nil - case .modularSmall: - let modularSmall = CLKComplicationTemplateModularSmallStackText() - modularSmall.line1TextProvider = glucoseText - modularSmall.line2TextProvider = timeText - template = modularSmall - case .modularLarge: - let modularSmall = CLKComplicationTemplateModularLargeTallBody() - modularSmall.bodyTextProvider = glucoseText - modularSmall.headerTextProvider = timeText - template = modularSmall - case .circularSmall: - let circularSmall = CLKComplicationTemplateCircularSmallSimpleText() - circularSmall.textProvider = glucoseText - template = circularSmall - case .extraLarge: - let extraLarge = CLKComplicationTemplateExtraLargeStackText() - extraLarge.line1TextProvider = glucoseText - extraLarge.line2TextProvider = timeText - template = extraLarge - case .utilitarianSmall, .utilitarianSmallFlat: - let utilitarianSmallFlat = CLKComplicationTemplateUtilitarianSmallFlat() - utilitarianSmallFlat.textProvider = glucoseText - template = utilitarianSmallFlat - case .utilitarianLarge: - let utilitarianLarge = CLKComplicationTemplateUtilitarianLargeFlat() - let eventualGlucoseText = CLKSimpleTextProvider.localizableTextProvider(withStringsFileTextKey: "75") - utilitarianLarge.textProvider = CLKSimpleTextProvider.localizableTextProvider(withStringsFileFormatKey: "UtilitarianLargeFlat", textProviders: [glucoseText, eventualGlucoseText, CLKTimeTextProvider(date: Date())]) - template = utilitarianLarge - } - - template?.tintColor = UIColor.tintColor - handler(template) - - } -} From a3dd64aa2b323eea5bebbe1458211bd4270af230 Mon Sep 17 00:00:00 2001 From: apabari Date: Mon, 15 Oct 2018 13:13:13 -0400 Subject: [PATCH 4/7] Delete Info.plist --- Info.plist | 56 ------------------------------------------------------ 1 file changed, 56 deletions(-) delete mode 100644 Info.plist diff --git a/Info.plist b/Info.plist deleted file mode 100644 index d9ff34f6f8..0000000000 --- a/Info.plist +++ /dev/null @@ -1,56 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleDisplayName - WatchApp Extension - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - XPC! - CFBundleShortVersionString - 1.9.3 - CFBundleSignature - ???? - CFBundleVersion - $(CURRENT_PROJECT_VERSION) - CLKComplicationPrincipalClass - $(PRODUCT_MODULE_NAME).ComplicationController - CLKComplicationSupportedFamilies - - CLKComplicationFamilyCircularSmall - CLKComplicationFamilyExtraLarge - CLKComplicationFamilyGraphicBezel - CLKComplicationFamilyGraphicCircular - CLKComplicationFamilyGraphicCorner - CLKComplicationFamilyGraphicRectangular - CLKComplicationFamilyModularLarge - CLKComplicationFamilyModularSmall - CLKComplicationFamilyUtilitarianLarge - CLKComplicationFamilyUtilitarianSmall - CLKComplicationFamilyUtilitarianSmallFlat - - NSExtension - - NSExtensionAttributes - - WKAppBundleIdentifier - $(MAIN_APP_BUNDLE_IDENTIFIER).LoopWatch - - NSExtensionPointIdentifier - com.apple.watchkit - - RemoteInterfacePrincipalClass - $(PRODUCT_MODULE_NAME).StatusInterfaceController - WKExtensionDelegateClassName - $(PRODUCT_MODULE_NAME).ExtensionDelegate - - From d678c5f5a3d3c6e3f74e6d932b61d43a0d7729d7 Mon Sep 17 00:00:00 2001 From: apabari Date: Mon, 15 Oct 2018 13:13:24 -0400 Subject: [PATCH 5/7] Delete CLKComplicationTemplate.swift --- CLKComplicationTemplate.swift | 133 ---------------------------------- 1 file changed, 133 deletions(-) delete mode 100644 CLKComplicationTemplate.swift diff --git a/CLKComplicationTemplate.swift b/CLKComplicationTemplate.swift deleted file mode 100644 index 758a643f2d..0000000000 --- a/CLKComplicationTemplate.swift +++ /dev/null @@ -1,133 +0,0 @@ -// -// CLKComplicationTemplate.swift -// Naterade -// -// Created by Nathan Racklyeft on 11/26/15. -// Copyright © 2015 Nathan Racklyeft. All rights reserved. -// - -import ClockKit -import HealthKit -import LoopKit -import Foundation - - -extension CLKComplicationTemplate { - - static func templateForFamily(_ family: CLKComplicationFamily, from context: WatchContext) -> CLKComplicationTemplate? { - guard let glucose = context.glucose, let unit = context.preferredGlucoseUnit else { - return nil - } - - return templateForFamily(family, glucose: glucose, unit: unit, date: context.glucoseDate, trend: context.glucoseTrend, eventualGlucose: context.eventualGlucose) - } - - static func templateForFamily(_ family: CLKComplicationFamily, glucose: HKQuantity, unit: HKUnit, date: Date?, trend: GlucoseTrend?, eventualGlucose: HKQuantity?) -> CLKComplicationTemplate? { - - let formatter = NumberFormatter.glucoseFormatter(for: unit) - - guard let glucoseString = formatter.string(from: glucose.doubleValue(for: unit)), - let date = date else - { - return nil - } - - let glucoseAndTrend = "\(glucoseString)\(trend?.symbol ?? " ")" - var accessibilityStrings = [glucoseString] - - if let trend = trend { - accessibilityStrings.append(trend.localizedDescription) - } - - let glucoseAndTrendText = CLKSimpleTextProvider(text: glucoseAndTrend, shortText: glucoseString, accessibilityLabel: accessibilityStrings.joined(separator: ", ")) - let timeText = CLKRelativeDateTextProvider(date: date, style: .natural, units: .minute) - - let timeFormatter = DateFormatter() - timeFormatter.dateStyle = .none - timeFormatter.timeStyle = .short - - - switch family { - case .graphicCorner: - // *************************************** - // ** Apple Watch Series 4 Complication ** - // *************************************** - // Corner Text - // Outer Text: Current Glucose and Trend - // Inner Text: timeText - - if #available(watchOSApplicationExtension 5.0, *) { - let cornerTemplate = CLKComplicationTemplateGraphicCornerStackText() - cornerTemplate.outerTextProvider = glucoseAndTrendText - cornerTemplate.outerTextProvider.tintColor = .green - cornerTemplate.innerTextProvider = timeText - return cornerTemplate - } else { - // Fallback on earlier versions - return nil - } - case .graphicCircular: - // *************************************** - // ** Apple Watch Series 4 Complication ** - // *************************************** - // Circular Gauge - // Full Ring - // Current Glucose in Center, Trend Arrow Below - // * future enhancement - update gauge colors to reflect loop status, or time in range for the day - if #available(watchOSApplicationExtension 5.0, *) { - let circularTemplate = CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText() - circularTemplate.gaugeProvider = CLKSimpleGaugeProvider(style: .fill, gaugeColor: .green, fillFraction: 1) - circularTemplate.centerTextProvider = CLKSimpleTextProvider(text: glucoseString) - circularTemplate.bottomTextProvider = CLKSimpleTextProvider(text: (trend?.symbol ?? " ")) - return circularTemplate - } else { - // Fallback on earlier versions - return nil - } - case .graphicRectangular, .graphicBezel: - return nil - case .modularSmall: - let template = CLKComplicationTemplateModularSmallStackText() - template.line1TextProvider = glucoseAndTrendText - template.line2TextProvider = timeText - return template - case .modularLarge: - let template = CLKComplicationTemplateModularLargeTallBody() - template.bodyTextProvider = glucoseAndTrendText - template.headerTextProvider = timeText - return template - case .circularSmall: - let template = CLKComplicationTemplateCircularSmallSimpleText() - template.textProvider = CLKSimpleTextProvider(text: glucoseString) - return template - case .extraLarge: - let template = CLKComplicationTemplateExtraLargeStackText() - template.line1TextProvider = glucoseAndTrendText - template.line2TextProvider = timeText - return template - case .utilitarianSmall, .utilitarianSmallFlat: - let template = CLKComplicationTemplateUtilitarianSmallFlat() - template.textProvider = CLKSimpleTextProvider(text: glucoseString) - - return template - case .utilitarianLarge: - var eventualGlucoseText = "" - if let eventualGlucose = eventualGlucose, - let eventualGlucoseString = formatter.string(from: eventualGlucose.doubleValue(for: unit)) - { - eventualGlucoseText = eventualGlucoseString - } - - let template = CLKComplicationTemplateUtilitarianLargeFlat() - let format = NSLocalizedString("UtilitarianLargeFlat", tableName: "ckcomplication", comment: "Utilitarian large flat format string (1: Glucose & Trend symbol) (2: Eventual Glucose) (3: Time)") - - template.textProvider = CLKSimpleTextProvider(text: String(format: format, arguments: [ - glucoseAndTrend, - eventualGlucoseText, - timeFormatter.string(from: date) - ] - )) - return template - } - } -} From 693f9f3576c7ecd853f0cfbf111d6470023963b0 Mon Sep 17 00:00:00 2001 From: apabari Date: Mon, 15 Oct 2018 13:16:00 -0400 Subject: [PATCH 6/7] Support for Apple Watch Complications --> .graphicCircular complication (full ring, glucose in middle, trend below) --> .graphicCorner complication (outer text: glucose and trend, inner text: time) --- .../Extensions/CLKComplicationTemplate.swift | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/WatchApp Extension/Extensions/CLKComplicationTemplate.swift b/WatchApp Extension/Extensions/CLKComplicationTemplate.swift index 1a3e54331f..758a643f2d 100644 --- a/WatchApp Extension/Extensions/CLKComplicationTemplate.swift +++ b/WatchApp Extension/Extensions/CLKComplicationTemplate.swift @@ -46,8 +46,45 @@ extension CLKComplicationTemplate { timeFormatter.dateStyle = .none timeFormatter.timeStyle = .short + switch family { - case .graphicCorner, .graphicCircular, .graphicRectangular, .graphicBezel: + case .graphicCorner: + // *************************************** + // ** Apple Watch Series 4 Complication ** + // *************************************** + // Corner Text + // Outer Text: Current Glucose and Trend + // Inner Text: timeText + + if #available(watchOSApplicationExtension 5.0, *) { + let cornerTemplate = CLKComplicationTemplateGraphicCornerStackText() + cornerTemplate.outerTextProvider = glucoseAndTrendText + cornerTemplate.outerTextProvider.tintColor = .green + cornerTemplate.innerTextProvider = timeText + return cornerTemplate + } else { + // Fallback on earlier versions + return nil + } + case .graphicCircular: + // *************************************** + // ** Apple Watch Series 4 Complication ** + // *************************************** + // Circular Gauge + // Full Ring + // Current Glucose in Center, Trend Arrow Below + // * future enhancement - update gauge colors to reflect loop status, or time in range for the day + if #available(watchOSApplicationExtension 5.0, *) { + let circularTemplate = CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText() + circularTemplate.gaugeProvider = CLKSimpleGaugeProvider(style: .fill, gaugeColor: .green, fillFraction: 1) + circularTemplate.centerTextProvider = CLKSimpleTextProvider(text: glucoseString) + circularTemplate.bottomTextProvider = CLKSimpleTextProvider(text: (trend?.symbol ?? " ")) + return circularTemplate + } else { + // Fallback on earlier versions + return nil + } + case .graphicRectangular, .graphicBezel: return nil case .modularSmall: let template = CLKComplicationTemplateModularSmallStackText() From 6a6d45c16d0d334cbce5eb4d401af5134a17a005 Mon Sep 17 00:00:00 2001 From: apabari Date: Mon, 15 Oct 2018 13:18:03 -0400 Subject: [PATCH 7/7] Support for Apple Watch Series 4 Complications --> .graphicCircular complication (full ring, glucose in middle, trend below) --> .graphicCorner complication (outer text: glucose and trend, inner text: time) --- .../ComplicationController.swift | 26 ++++++++++++++++++- WatchApp Extension/Info.plist | 10 ++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/WatchApp Extension/ComplicationController.swift b/WatchApp Extension/ComplicationController.swift index 4b149cabb1..d632954571 100644 --- a/WatchApp Extension/ComplicationController.swift +++ b/WatchApp Extension/ComplicationController.swift @@ -92,7 +92,30 @@ final class ComplicationController: NSObject, CLKComplicationDataSource { let timeText = CLKRelativeDateTextProvider(date: Date(), style: .natural, units: .minute) switch complication.family { - case .graphicCorner, .graphicCircular, .graphicRectangular, .graphicBezel: + + case .graphicCorner: + if #available(watchOSApplicationExtension 5.0, *) { + let cornerTemplate = CLKComplicationTemplateGraphicCornerStackText() + cornerTemplate.outerTextProvider = glucoseText + cornerTemplate.innerTextProvider = timeText + cornerTemplate.outerTextProvider.tintColor = .green + template = cornerTemplate + } else { + // Fallback on earlier versions + template = nil + } + case .graphicCircular: + if #available(watchOSApplicationExtension 5.0, *) { + let circularTemplate = CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText() + circularTemplate.gaugeProvider = CLKSimpleGaugeProvider(style: .fill, gaugeColor: .green, fillFraction: 1) + circularTemplate.centerTextProvider = CLKSimpleTextProvider(text: "120") + circularTemplate.bottomTextProvider = CLKSimpleTextProvider(text: "↘︎") + template = circularTemplate + } else { + // Fallback on earlier versions + template = nil + } + case .graphicRectangular, .graphicBezel: template = nil case .modularSmall: let modularSmall = CLKComplicationTemplateModularSmallStackText() @@ -126,5 +149,6 @@ final class ComplicationController: NSObject, CLKComplicationDataSource { template?.tintColor = UIColor.tintColor handler(template) + } } diff --git a/WatchApp Extension/Info.plist b/WatchApp Extension/Info.plist index 72ad48bfe9..d9ff34f6f8 100644 --- a/WatchApp Extension/Info.plist +++ b/WatchApp Extension/Info.plist @@ -26,13 +26,17 @@ $(PRODUCT_MODULE_NAME).ComplicationController CLKComplicationSupportedFamilies - CLKComplicationFamilyModularSmall CLKComplicationFamilyCircularSmall CLKComplicationFamilyExtraLarge - CLKComplicationFamilyUtilitarianSmallFlat - CLKComplicationFamilyUtilitarianLarge + CLKComplicationFamilyGraphicBezel + CLKComplicationFamilyGraphicCircular + CLKComplicationFamilyGraphicCorner + CLKComplicationFamilyGraphicRectangular CLKComplicationFamilyModularLarge + CLKComplicationFamilyModularSmall + CLKComplicationFamilyUtilitarianLarge CLKComplicationFamilyUtilitarianSmall + CLKComplicationFamilyUtilitarianSmallFlat NSExtension