ComplicationController.swift 2.4 KB

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