Created
April 23, 2018 15:34
-
-
Save mlcollard/283cc0a75a75e077ca21e89416be914f to your computer and use it in GitHub Desktop.
This file contains 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 Configuration | |
var startTime = Date() | |
func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) { | |
handler([.forward, .backward]) | |
} | |
func getTimelineStartDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) { | |
handler(startTime.addingTimeInterval(-(60.0 * 60.0 * 10))) | |
} | |
func getTimelineEndDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) { | |
handler(startTime.addingTimeInterval(60.0 * 60.0 * 10)) | |
} | |
func getPrivacyBehavior(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationPrivacyBehavior) -> Void) { | |
handler(.showOnLockScreen) | |
} | |
// MARK: - Timeline Population | |
func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) { | |
let template = CLKComplicationTemplateModularSmallRingText() | |
template.textProvider = CLKSimpleTextProvider(text: "UA") | |
let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template) | |
handler(timelineEntry) | |
} | |
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 | |
let template = CLKComplicationTemplateModularSmallRingText() | |
var timelineEntries: [CLKComplicationTimelineEntry] = [] | |
for hour in 1...10 { | |
template.textProvider = CLKSimpleTextProvider(text: "-" + String(hour)) | |
timelineEntries.append(CLKComplicationTimelineEntry(date: Date(timeIntervalSinceNow: (TimeInterval(60 * 60 * -hour))), complicationTemplate: template)) | |
} | |
handler(timelineEntries) | |
} | |
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 template = CLKComplicationTemplateModularSmallRingText() | |
var timelineEntries: [CLKComplicationTimelineEntry] = [] | |
for hour in 1...10 { | |
template.textProvider = CLKSimpleTextProvider(text: String(hour)) | |
timelineEntries.append(CLKComplicationTimelineEntry(date: Date(timeIntervalSinceNow: (TimeInterval(60 * 60 * hour))), complicationTemplate: template)) | |
} | |
handler(timelineEntries) | |
} | |
// MARK: - Placeholder Templates | |
func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) { | |
// This method will be called once per supported complication, and the results will be cached | |
switch complication.family { | |
case .modularSmall: | |
print("HERE \(#function)") | |
let modularSmallTemplate = CLKComplicationTemplateModularSmallRingText() | |
modularSmallTemplate.textProvider = CLKSimpleTextProvider(text: "UA") | |
handler(modularSmallTemplate) | |
default: | |
handler(nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment