swift – 启动App的WatchOS3复杂功能
发布时间:2020-12-14 04:49:30 所属栏目:百科 来源:网络整理
导读:我想为watchOS 3创建一个复杂功能,只需启动我的应用程序.我用XCode创建了ComplicationController: class ComplicationController: NSObject,CLKComplicationDataSource{ // MARK: - Timeline Configuration func getSupportedTimeTravelDirections(for comp
我想为watchOS 3创建一个复杂功能,只需启动我的应用程序.我用XCode创建了ComplicationController:
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,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) } } 并为Circular,Modular和Utilitarian资产添加了图像.但是当我运行Watch App时,我无法选择Watch脸的并发症.我还需要做什么? 谢谢 格雷格 解决方法
这些代码更改是必需的:
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) } } 此外,您需要在扩展中提供图像作为资产. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ruby-on-rails – 将OrientDB的JDBC驱动程序与ActiveRecord
- Flex eclipse 开发环境搭建
- Nand Flash Yaffs系统大量写入数据失败问题的解决方法。
- ruby-on-rails-3 – 在Ruby on Rails 3 / Postgres / Apach
- ruby-on-rails – Rails:设计:如何编辑用户信息?
- c – 如何在默认构造函数中初始化引用成员?
- ruby-on-rails – ruby??包括vs扩展
- 定期从Oracle导数据至MySQL
- ruby-on-rails – 使用capistrano在生产中运行rpush作为守护
- Ruby库来监视系统资源