ComplicationController.swift 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
  18. handler([.forward, .backward])
  19. }
  20. func getTimelineStartDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {
  21. handler(nil)
  22. }
  23. func getTimelineEndDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) {
  24. handler(nil)
  25. }
  26. func getPrivacyBehavior(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationPrivacyBehavior) -> Void) {
  27. handler(.showOnLockScreen)
  28. }
  29. // MARK: - Timeline Population
  30. func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
  31. // Call the handler with the current timeline entry
  32. handler(nil)
  33. }
  34. func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
  35. // Call the handler with the timeline entries prior to the given date
  36. handler(nil)
  37. }
  38. func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
  39. // Call the handler with the timeline entries after to the given date
  40. handler(nil)
  41. }
  42. // MARK: - Placeholder Templates
  43. func getLocalizableSampleTemplate(for complication: 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. }