2016-09-26 59 views
3

我想創建一個複雜功能的watchOS 3,將簡單地啓動我的應用程序。我已經使用的XCode創建ComplicationController:WatchOS3複雜的啓動應用程序

class ComplicationController: NSObject, CLKComplicationDataSource 
{ 

    // MARK: - Timeline Configuration 

    func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) { 
     handler([.forward, .backward]) 
    } 

    func getTimelineStartDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) { 
     handler(nil) 
    } 

    func getTimelineEndDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -> Void) { 
     handler(nil) 
    } 

    func getPrivacyBehavior(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationPrivacyBehavior) -> Void) { 
     handler(.showOnLockScreen) 
    } 

    // MARK: - Timeline Population 

    func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) { 
     // Call the handler with the current timeline entry 
     handler(nil) 
    } 

    func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) { 
     // Call the handler with the timeline entries prior to the given date 
     handler(nil) 
    } 

    func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) { 
     // Call the handler with the timeline entries after to the given date 
     handler(nil) 
    } 

    // MARK: - Placeholder Templates 

    func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) { 
     // This method will be called once per supported complication, and the results will be cached 
     handler(nil) 
    } 

} 

,並添加圖像爲圓形,模塊化和功利的資產。但是當我運行手錶應用時,我無法選擇手錶表面的複雜情況。我還需要做什麼?

感謝

格雷格

回答

7

需要這些代碼更改:

func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) 
{ 
    handler([]) 
} 


func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) 
{ 
    if complication.family == .circularSmall 
    { 

     let template = CLKComplicationTemplateCircularSmallRingImage() 
     template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Circular")!) 
     let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template) 
     handler(timelineEntry) 

    } else if complication.family == .utilitarianSmall 
    { 

     let template = CLKComplicationTemplateUtilitarianSmallRingImage() 
     template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Utilitarian")!) 
     let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template) 
     handler(timelineEntry) 

    } else if complication.family == .modularSmall 
    { 

     let template = CLKComplicationTemplateModularSmallRingImage() 
     template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Modular")!) 
     let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template) 
     handler(timelineEntry) 

    } else { 

     handler(nil) 

    } 

} 


func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) 
{   
    switch complication.family 
    { 
     case .circularSmall: 
      let image: UIImage = UIImage(named: "Circular")! 
      let template = CLKComplicationTemplateCircularSmallSimpleImage() 
      template.imageProvider = CLKImageProvider(onePieceImage: image) 
      handler(template) 
     case .utilitarianSmall: 
      let image: UIImage = UIImage(named: "Utilitarian")! 
      let template = CLKComplicationTemplateUtilitarianSmallSquare() 
      template.imageProvider = CLKImageProvider(onePieceImage: image) 
      handler(template) 
     case .modularSmall: 
      let image: UIImage = UIImage(named: "Modular")! 
      let template = CLKComplicationTemplateModularSmallSimpleImage() 
      template.imageProvider = CLKImageProvider(onePieceImage: image) 
      handler(template) 
     default: 
      handler(nil) 
    } 
} 

另外,您需要提供的圖像作爲擴展資產。