ComplicationController.swift 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import ClockKit
  15. class ComplicationController: NSObject, CLKComplicationDataSource {
  16. // MARK: - Complication Configuration
  17. func getComplicationDescriptors(handler: @escaping ([CLKComplicationDescriptor]) -> Void) {
  18. let descriptors = [
  19. CLKComplicationDescriptor(
  20. identifier: "complication",
  21. displayName: "AdvancedSample",
  22. supportedFamilies: CLKComplicationFamily.allCases
  23. ),
  24. // Multiple complication support can be added here with more descriptors
  25. ]
  26. // Call the handler with the currently supported complication descriptors
  27. handler(descriptors)
  28. }
  29. func handleSharedComplicationDescriptors(_ complicationDescriptors: [CLKComplicationDescriptor]) {
  30. // Do any necessary work to support these newly shared complication descriptors
  31. }
  32. // MARK: - Timeline Configuration
  33. func getTimelineEndDate(for complication: CLKComplication,
  34. withHandler handler: @escaping (Date?) -> Void) {
  35. // Call the handler with the last entry date you can currently provide or nil if you can't support future timelines
  36. handler(nil)
  37. }
  38. func getPrivacyBehavior(for complication: CLKComplication,
  39. withHandler handler: @escaping (CLKComplicationPrivacyBehavior)
  40. -> Void) {
  41. // Call the handler with your desired behavior when the device is locked
  42. handler(.showOnLockScreen)
  43. }
  44. // MARK: - Timeline Population
  45. func getCurrentTimelineEntry(for complication: CLKComplication,
  46. withHandler handler: @escaping (CLKComplicationTimelineEntry?)
  47. -> Void) {
  48. // Call the handler with the current timeline entry
  49. handler(nil)
  50. }
  51. func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int,
  52. withHandler handler: @escaping ([CLKComplicationTimelineEntry]?)
  53. -> Void) {
  54. // Call the handler with the timeline entries after the given date
  55. handler(nil)
  56. }
  57. // MARK: - Sample Templates
  58. func getLocalizableSampleTemplate(for complication: CLKComplication,
  59. withHandler handler: @escaping (CLKComplicationTemplate?)
  60. -> Void) {
  61. // This method will be called once per supported complication, and the results will be cached
  62. handler(nil)
  63. }
  64. }