我在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)
}
}
}
}
答案 0 :(得分:4)
您和我同时遇到此问题。在此页面上:
https://forums.developer.apple.com/thread/108598
在手表扩展程序的ClockKit.framework
阶段将Link Binary With Libraries
添加为可选。这样就解决了我的问题。