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) 
    } 

} 

원형, 모듈 및 실용 자산에 대한 이미지가 추가되었습니다. 그러나 Watch App을 실행할 때 Watch면에 대한 합병증을 선택할 수는 없습니다. 나는 무엇을해야 하는가?

감사

그렉

이 코드 변경이 필요

답변

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) 
    } 
} 

플러스 당신은 확장의 자산으로 이미지를 제공해야합니다.