ComplicationController.swift 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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
  36. // support future timelines
  37. handler(nil)
  38. }
  39. func getPrivacyBehavior(for complication: CLKComplication,
  40. withHandler handler: @escaping (CLKComplicationPrivacyBehavior)
  41. -> Void) {
  42. // Call the handler with your desired behavior when the device is locked
  43. handler(.showOnLockScreen)
  44. }
  45. // MARK: - Timeline Population
  46. func getCurrentTimelineEntry(for complication: CLKComplication,
  47. withHandler handler: @escaping (CLKComplicationTimelineEntry?)
  48. -> Void) {
  49. // Call the handler with the current timeline entry
  50. handler(nil)
  51. }
  52. func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int,
  53. withHandler handler: @escaping ([CLKComplicationTimelineEntry]?)
  54. -> Void) {
  55. // Call the handler with the timeline entries after the given date
  56. handler(nil)
  57. }
  58. // MARK: - Sample Templates
  59. func getLocalizableSampleTemplate(for complication: CLKComplication,
  60. withHandler handler: @escaping (CLKComplicationTemplate?)
  61. -> Void) {
  62. // This method will be called once per supported complication, and the results will be cached
  63. handler(nil)
  64. }
  65. }