ComplicationController.swift 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import ClockKit
  2. class ComplicationController: NSObject, CLKComplicationDataSource {
  3. // MARK: - Complication Configuration
  4. func getComplicationDescriptors(handler: @escaping ([CLKComplicationDescriptor]) -> Void) {
  5. let descriptors = [
  6. CLKComplicationDescriptor(
  7. identifier: "complication",
  8. displayName: "FreeAPS",
  9. supportedFamilies: CLKComplicationFamily.allCases
  10. )
  11. // Multiple complication support can be added here with more descriptors
  12. ]
  13. // Call the handler with the currently supported complication descriptors
  14. handler(descriptors)
  15. }
  16. func handleSharedComplicationDescriptors(_: [CLKComplicationDescriptor]) {
  17. // Do any necessary work to support these newly shared complication descriptors
  18. }
  19. // MARK: - Timeline Configuration
  20. func getTimelineEndDate(for _: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {
  21. // Call the handler with the last entry date you can currently provide or nil if you can't support future timelines
  22. handler(nil)
  23. }
  24. func getPrivacyBehavior(for _: CLKComplication, withHandler handler: @escaping (CLKComplicationPrivacyBehavior) -> Void) {
  25. // Call the handler with your desired behavior when the device is locked
  26. handler(.showOnLockScreen)
  27. }
  28. // MARK: - Timeline Population
  29. func getCurrentTimelineEntry(for _: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
  30. // Call the handler with the current timeline entry
  31. handler(nil)
  32. }
  33. func getTimelineEntries(
  34. for _: CLKComplication,
  35. after _: Date,
  36. limit _: Int,
  37. withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void
  38. ) {
  39. // Call the handler with the timeline entries after the given date
  40. handler(nil)
  41. }
  42. // MARK: - Sample Templates
  43. func getLocalizableSampleTemplate(for _: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {
  44. // This method will be called once per supported complication, and the results will be cached
  45. handler(nil)
  46. }
  47. }