Watch Complication 导致 dyld 崩溃:找不到符号:_OBJC_CLASS_$_CLKFullColorImageProvider

Posted

技术标签:

【中文标题】Watch Complication 导致 dyld 崩溃:找不到符号:_OBJC_CLASS_$_CLKFullColorImageProvider【英文标题】:Watch Complication causes crash with dyld: Symbol not found: _OBJC_CLASS_$_CLKFullColorImageProvider 【发布时间】:2018-10-26 17:15:09 【问题描述】:

我在 watchOS 4 中收到此错误 dyld: Symbol not found: _OBJC_CLASS_$_CLKFullColorImageProvider,但在 watchOS 5 中没有,我相信它与下面的复杂代码有关,但无法弄清楚为什么……据我所知编译器应该不要寻找CLKFullColorImageProvider,因为我已经用if #available(watchOSApplicationExtension 5.0, *) 阻止了它

class Complication: NSObject, CLKComplicationDataSource 
    func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) 
        if #available(watchOSApplicationExtension 5.0, *) 
            if complication.family == .circularSmall 

                let template = CLKComplicationTemplateCircularSmallRingImage()
                guard let image = UIImage(named: "Circular") else  handler(nil); return
                template.imageProvider = CLKImageProvider(onePieceImage: image)
                let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
                handler(timelineEntry)

             else if complication.family == .utilitarianSmall 

                let template = CLKComplicationTemplateUtilitarianSmallRingImage()
                guard let image = UIImage(named: "Utilitarian") else  handler(nil); return
                template.imageProvider = CLKImageProvider(onePieceImage: image)
                let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
                handler(timelineEntry)

             else if complication.family == .modularSmall 

                let template = CLKComplicationTemplateModularSmallRingImage()
                guard let image = UIImage(named: "Modular") else  handler(nil); return
                template.imageProvider = CLKImageProvider(onePieceImage: image)
                let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
                handler(timelineEntry)

             else if complication.family == .graphicCircular 
                let template = CLKComplicationTemplateGraphicCircularImage()
                guard let image = UIImage(named: "GraphicCircular") else  handler(nil); return
                template.imageProvider = CLKFullColorImageProvider(fullColorImage: image)
                let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
                handler(timelineEntry)

             else if complication.family == .graphicBezel 
                let template = CLKComplicationTemplateModularSmallRingImage()
                guard let image = UIImage(named: "GraphicBezel") else  handler(nil); return
                template.imageProvider = CLKImageProvider(onePieceImage: image)
                let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
                handler(timelineEntry)

             else if complication.family == .graphicCorner 
                let template = CLKComplicationTemplateGraphicCornerCircularImage()
                guard let image = UIImage(named: "GraphicCorner") else  handler(nil); return
                template.imageProvider = CLKFullColorImageProvider(fullColorImage: image)
                let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
                handler(timelineEntry)

             else 

                handler(nil)

            
         else 

            if complication.family == .circularSmall 

                let template = CLKComplicationTemplateCircularSmallRingImage()
                guard let image = UIImage(named: "Circular") else  handler(nil); return
                template.imageProvider = CLKImageProvider(onePieceImage: image)
                let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
                handler(timelineEntry)

             else if complication.family == .utilitarianSmall 

                let template = CLKComplicationTemplateUtilitarianSmallRingImage()
                guard let image = UIImage(named: "Utilitarian") else  handler(nil); return
                template.imageProvider = CLKImageProvider(onePieceImage: image)
                let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
                handler(timelineEntry)

             else if complication.family == .modularSmall 

                let template = CLKComplicationTemplateModularSmallRingImage()
                guard let image = UIImage(named: "Modular") else  handler(nil); return
                template.imageProvider = CLKImageProvider(onePieceImage: image)
                let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
                handler(timelineEntry)

             else 

                handler(nil)

            
        
    

    func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) 
        handler([])
    
    func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) 
        if #available(watchOSApplicationExtension 5.0, *) 
            if complication.family == .circularSmall 

                let template = CLKComplicationTemplateCircularSmallRingImage()
                guard let image = UIImage(named: "Circular") else  handler(nil); return
                template.imageProvider = CLKImageProvider(onePieceImage: image)
                handler(template)

             else if complication.family == .utilitarianSmall 

                let template = CLKComplicationTemplateUtilitarianSmallRingImage()
                guard let image = UIImage(named: "Utilitarian") else  handler(nil); return
                template.imageProvider = CLKImageProvider(onePieceImage: image)
                handler(template)

             else if complication.family == .modularSmall 

                let template = CLKComplicationTemplateModularSmallRingImage()
                guard let image = UIImage(named: "Modular") else  handler(nil); return
                template.imageProvider = CLKImageProvider(onePieceImage: image)
                handler(template)

             else if complication.family == .graphicCircular 
                let template = CLKComplicationTemplateGraphicCircularImage()
                guard let image = UIImage(named: "GraphicCircular") else  handler(nil); return
                template.imageProvider = CLKFullColorImageProvider(fullColorImage: image)
                handler(template)

             else if complication.family == .graphicBezel 
                let template = CLKComplicationTemplateModularSmallRingImage()
                guard let image = UIImage(named: "GraphicBezel") else  handler(nil); return
                template.imageProvider = CLKImageProvider(onePieceImage: image)
                handler(template)

             else if complication.family == .graphicCorner 
                let template = CLKComplicationTemplateGraphicCornerCircularImage()
                guard let image = UIImage(named: "GraphicCorner") else  handler(nil); return
                template.imageProvider = CLKFullColorImageProvider(fullColorImage: image)
                handler(template)

             else 

                handler(nil)

            
         else 
            if complication.family == .circularSmall 

                let template = CLKComplicationTemplateCircularSmallRingImage()
                guard let image = UIImage(named: "Circular") else  handler(nil); return
                template.imageProvider = CLKImageProvider(onePieceImage: image)
                handler(template)

             else if complication.family == .utilitarianSmall 

                let template = CLKComplicationTemplateUtilitarianSmallRingImage()
                guard let image = UIImage(named: "Utilitarian") else  handler(nil); return
                template.imageProvider = CLKImageProvider(onePieceImage: image)
                handler(template)

             else if complication.family == .modularSmall 

                let template = CLKComplicationTemplateModularSmallRingImage()
                guard let image = UIImage(named: "Modular") else  handler(nil); return
                template.imageProvider = CLKImageProvider(onePieceImage: image)
                handler(template)

             else 

                handler(nil)

            
        


    








【问题讨论】:

【参考方案1】:

你和我同时遇到了这个问题。从这个页面:

https://forums.developer.apple.com/thread/108598

在手表扩展的Link Binary With Libraries 阶段将ClockKit.framework 添加为可选。这立即解决了我的问题。

【讨论】:

以上是关于Watch Complication 导致 dyld 崩溃:找不到符号:_OBJC_CLASS_$_CLKFullColorImageProvider的主要内容,如果未能解决你的问题,请参考以下文章

WatchKit Complication:从扩展委托获取复杂数据

Shopware 6:bin/watch-storefront.sh 导致 chrome 出现 CORS 错误

Webpack 在编译 typescript 代码失败时会导致 gulp watch 崩溃

vue实现简单防抖(watch input)

vue之watch实现原理

Xcode最新版“泄密”:Apple Watch Series 5使用与上代相同的处理器!