WatchOS3 Complication that launches App

后端 未结 3 891
夕颜
夕颜 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:35

    Apple Watch 4 new graphic complications looks like this:

    func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
        // Call the handler with the current timeline entry
        switch complication.family {
        case .graphicCorner:
            if #available(watchOSApplicationExtension 5.0, *) {
                let template = CLKComplicationTemplateGraphicCornerCircularImage()
                let image = UIImage(named: "Complication/Graphic Corner")!
                template.imageProvider = CLKFullColorImageProvider(fullColorImage: image)
                let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
                handler(timelineEntry)
            } else {
                handler(nil)
            }
        case .graphicCircular:
            if #available(watchOSApplicationExtension 5.0, *) {
                let template = CLKComplicationTemplateGraphicCircularImage()
                let image = UIImage(named: "Complication/Graphic Circular")!
                template.imageProvider = CLKFullColorImageProvider(fullColorImage: image)
                let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
                handler(timelineEntry)
            } else {
                handler(nil)
            }
        default:
            handler(nil)
        }
    }
    
    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
        switch complication.family {
        case .graphicCorner:
            if #available(watchOSApplicationExtension 5.0, *) {
                let template = CLKComplicationTemplateGraphicCornerCircularImage()
                let image = UIImage(named: "Complication/Graphic Corner")!
                template.imageProvider = CLKFullColorImageProvider(fullColorImage: image)
                handler(template)
            } else {
                handler(nil)
            }
        case .graphicCircular:
            if #available(watchOSApplicationExtension 5.0, *) {
                let template = CLKComplicationTemplateGraphicCircularImage()
                let image = UIImage(named: "Complication/Graphic Circular")!
                template.imageProvider = CLKFullColorImageProvider(fullColorImage: image)
                handler(template)
            } else {
                handler(nil)
            }
        default:
            handler(nil)
        }
    }
    

提交回复
热议问题