WatchOS3 Complication that launches App

后端 未结 3 885
夕颜
夕颜 2020-12-30 14:49

I would like to create a complication for watchOS 3 that will simply launch my App. I have used XCode to create the ComplicationController:

class Complicatio         


        
3条回答
  •  不思量自难忘°
    2020-12-30 15:40

    These code changes are required:

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

    Plus you need to provide the images as assets in the extension.

提交回复
热议问题