ComplicationController.swift 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2020 Google
  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: - Timeline Configuration
  17. func getSupportedTimeTravelDirections(for complication: CLKComplication,
  18. withHandler handler: @escaping (CLKComplicationTimeTravelDirections)
  19. -> Void) {
  20. handler([.forward, .backward])
  21. }
  22. func getTimelineStartDate(for complication: CLKComplication,
  23. withHandler handler: @escaping (Date?) -> Void) {
  24. handler(nil)
  25. }
  26. func getTimelineEndDate(for complication: CLKComplication,
  27. withHandler handler: @escaping (Date?) -> Void) {
  28. handler(nil)
  29. }
  30. func getPrivacyBehavior(for complication: CLKComplication,
  31. withHandler handler: @escaping (CLKComplicationPrivacyBehavior) -> Void) {
  32. handler(.showOnLockScreen)
  33. }
  34. // MARK: - Timeline Population
  35. func getCurrentTimelineEntry(for complication: CLKComplication,
  36. withHandler handler: @escaping (CLKComplicationTimelineEntry?)
  37. -> Void) {
  38. // Call the handler with the current timeline entry
  39. handler(nil)
  40. }
  41. func getTimelineEntries(for complication: CLKComplication,
  42. before date: Date,
  43. limit: Int,
  44. withHandler handler: @escaping ([CLKComplicationTimelineEntry]?)
  45. -> Void) {
  46. // Call the handler with the timeline entries prior to the given date
  47. handler(nil)
  48. }
  49. func getTimelineEntries(for complication: CLKComplication,
  50. after date: Date,
  51. limit: Int,
  52. withHandler handler: @escaping ([CLKComplicationTimelineEntry]?)
  53. -> Void) {
  54. // Call the handler with the timeline entries after to the given date
  55. handler(nil)
  56. }
  57. // MARK: - Placeholder 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. }