Last active
November 20, 2015 04:39
-
-
Save someoneAnyone/e01a9ed39c233791fc08 to your computer and use it in GitHub Desktop.
some ideas for mapping data for complications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - Timeline Population | |
func getCurrentTimelineEntryForComplication(complication: CLKComplication, withHandler handler: ((CLKComplicationTimelineEntry?) -> Void)) { | |
// Call the handler with the current timeline entry | |
#if DEBUG | |
print(">>> Entering \(__FUNCTION__) <<<") | |
print("complication family: \(complication.family)") | |
#endif | |
// let myDelegate = WKExtension.sharedExtension().delegate as! ExtensionDelegate | |
// var data : Dictionary = myDelegate.myComplicationData[ComplicationCurrentEntry]! | |
var entry : CLKComplicationTimelineEntry? | |
let now = NSDate() | |
let complicationFamily = complication.family | |
let sampleDisplayName = model.displayName | |
let sampleSGV = model.sgvStringWithEmoji | |
let sampleDelta = model.deltaString | |
let sampleRaw = model.rawString // only if available. | |
let sampleRawShort = "100 : C" | |
switch complicationFamily { | |
case .ModularSmall: | |
// CLKComplicationTemplateModularSmallStackImage | |
// CLKComplicationTemplateModularSmallStackText | |
let modularTemplate = CLKComplicationTemplateModularSmallStackText() | |
modularTemplate.line1TextProvider = CLKSimpleTextProvider(text: sampleSGV) | |
modularTemplate.line2TextProvider = CLKSimpleTextProvider(text: sampleDelta) | |
// Create the entry. | |
entry = CLKComplicationTimelineEntry(date: now, complicationTemplate: modularTemplate) | |
case .ModularLarge: | |
// CLKComplicationTemplateModularLargeColumns | |
// CLKComplicationTemplateModularLargeStandardBody | |
let modularTemplate = CLKComplicationTemplateModularLargeStandardBody() | |
modularTemplate.headerTextProvider = CLKSimpleTextProvider(text: sampleDisplayName) | |
modularTemplate.body1TextProvider = CLKSimpleTextProvider(text: sampleDelta) | |
modularTemplate.body2TextProvider = CLKSimpleTextProvider(text: sampleRaw, shortText: sampleRawShort) | |
// Create the entry. | |
entry = CLKComplicationTimelineEntry(date: now, complicationTemplate: modularTemplate) | |
case .UtilitarianSmall: | |
// CLKComplicationTemplateUtilitarianSmallFlat | |
let utilitarianSmall = CLKComplicationTemplateUtilitarianSmallFlat() | |
utilitarianSmall.textProvider = CLKSimpleTextProvider(text: sampleSGV) | |
// Create the entry. | |
entry = CLKComplicationTimelineEntry(date: now, complicationTemplate: utilitarianSmall) | |
case .UtilitarianLarge: | |
// CLKComplicationTemplateUtilitarianLargeFlat | |
let utilitarianLarge = CLKComplicationTemplateUtilitarianLargeFlat() | |
utilitarianLarge.textProvider = CLKSimpleTextProvider(text: sampleDisplayName + " " + sampleSGV + " " + sampleDelta + " " + sampleRaw) | |
entry = CLKComplicationTimelineEntry(date: now, complicationTemplate: utilitarianLarge) | |
case .CircularSmall: | |
let circularSmall = CLKComplicationTemplateCircularSmallStackText() | |
circularSmall.line1TextProvider = CLKSimpleTextProvider(text: sampleSGV) | |
circularSmall.line2TextProvider = CLKSimpleTextProvider(text: sampleDelta) | |
entry = CLKComplicationTimelineEntry(date: now, complicationTemplate: circularSmall) | |
} | |
handler(entry) | |
} | |
func getTimelineEntriesForComplication(complication: CLKComplication, beforeDate date: NSDate, limit: Int, withHandler handler: (([CLKComplicationTimelineEntry]?) -> Void)) { | |
// Call the handler with the timeline entries prior to the given date | |
handler(nil) | |
} | |
func getTimelineEntriesForComplication(complication: CLKComplication, afterDate date: NSDate, limit: Int, withHandler handler: (([CLKComplicationTimelineEntry]?) -> Void)) { | |
// Call the handler with the timeline entries after to the given date | |
handler(nil) | |
} | |
// MARK: - Update Scheduling | |
func getNextRequestedUpdateDateWithHandler(handler: (NSDate?) -> Void) { | |
// Call the handler with the date when you would next like to be given the opportunity to update your complication content | |
handler(nextUpdateRequest); | |
} | |
// MARK: - Placeholder Templates | |
func getPlaceholderTemplateForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTemplate?) -> Void) { | |
// This method will be called once per supported complication, and the results will be cached | |
#if DEBUG | |
print(">>> Entering \(__FUNCTION__) <<<") | |
print("complication family: \(complication.family)") | |
#endif | |
let sampleDisplayName = "Nightscout" | |
let sampleSGV = "---" | |
let sampleDelta = "- --/--" | |
let sampleRaw = "--- : ---" | |
let sampleRawShort = "100 : C" | |
var template : CLKComplicationTemplate? | |
let complicationFamily = complication.family | |
switch complicationFamily { | |
case .ModularSmall: | |
// CLKComplicationTemplateModularSmallStackImage | |
// CLKComplicationTemplateModularSmallStackText | |
let modularTemplate = CLKComplicationTemplateModularSmallStackText() | |
modularTemplate.line1TextProvider = CLKSimpleTextProvider(text: sampleSGV) | |
modularTemplate.line2TextProvider = CLKSimpleTextProvider(text: sampleDelta) | |
template = modularTemplate | |
case .ModularLarge: | |
// CLKComplicationTemplateModularLargeColumns | |
// CLKComplicationTemplateModularLargeStandardBody | |
let modularTemplate = CLKComplicationTemplateModularLargeStandardBody() | |
modularTemplate.headerTextProvider = CLKSimpleTextProvider(text: sampleDisplayName) | |
modularTemplate.body1TextProvider = CLKSimpleTextProvider(text: sampleDelta) | |
modularTemplate.body2TextProvider = CLKSimpleTextProvider(text: sampleRaw, shortText: sampleRawShort) | |
template = modularTemplate | |
case .UtilitarianSmall: | |
// CLKComplicationTemplateUtilitarianSmallFlat | |
let utilitarianSmall = CLKComplicationTemplateUtilitarianSmallFlat() | |
utilitarianSmall.textProvider = CLKSimpleTextProvider(text: sampleSGV) | |
template = utilitarianSmall | |
case .UtilitarianLarge: | |
// CLKComplicationTemplateUtilitarianLargeFlat | |
let utilitarianLarge = CLKComplicationTemplateUtilitarianLargeFlat() | |
utilitarianLarge.textProvider = CLKSimpleTextProvider(text: sampleDisplayName + " " + sampleSGV + " " + sampleDelta + " " + sampleRaw) | |
template = utilitarianLarge | |
case .CircularSmall: | |
let circularSmall = CLKComplicationTemplateCircularSmallStackText() | |
circularSmall.line1TextProvider = CLKSimpleTextProvider(text: sampleSGV) | |
circularSmall.line2TextProvider = CLKSimpleTextProvider(text: sampleDelta) | |
template = circularSmall | |
} | |
handler(template) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment