gpt4 book ai didi

swift - 复杂功能未出现在图库中

转载 作者:搜寻专家 更新时间:2023-11-01 06:17:27 25 4
gpt4 key购买 nike

从 Watch Face 启动我的应用程序时遇到了一些简单的问题。它不显示任何数据,只显示图像。我关注了Adding Complications to the Gallery指南,但我无法将我的复杂功能添加到 iPhone Watch 应用程序的复杂功能库中。

public func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {

guard let tempalte = buildTemplate(for: complication) else {
fatalError("Unsuported Complication Family.")
}
handler(tempalte)
}

// Helper function to build template.

fileprivate func buildTemplate(for complication: CLKComplication) -> CLKComplicationTemplate? {

let textProvider = CLKSimpleTextProvider.localizableTextProvider(withStringsFileTextKey: "Caffeine")

switch complication.family {
case .modularSmall:

let icon = #imageLiteral(resourceName: "Complication/Modular")

let complicationTemplate = CLKComplicationTemplateModularSmallSimpleImage()
complicationTemplate.imageProvider = CLKImageProvider(onePieceImage: icon)

return complicationTemplate

case .circularSmall:

let icon = #imageLiteral(resourceName: "Complication/Circular")

let complicationTemplate = CLKComplicationTemplateCircularSmallSimpleImage()
complicationTemplate.imageProvider = CLKImageProvider(onePieceImage: icon)
return complicationTemplate

case .utilitarianSmall:

let icon = #imageLiteral(resourceName: "Complication/Utilitarian")

let complicationTemplate = CLKComplicationTemplateUtilitarianSmallSquare()
complicationTemplate.imageProvider = CLKImageProvider(onePieceImage: icon)
return complicationTemplate

case .utilitarianLarge:

let icon = #imageLiteral(resourceName: "Complication/Utilitarian")

let complicationTemplate = CLKComplicationTemplateUtilitarianLargeFlat()
complicationTemplate.imageProvider = CLKImageProvider(onePieceImage: icon)
complicationTemplate.textProvider = textProvider
return complicationTemplate

case .utilitarianSmallFlat:

let icon = #imageLiteral(resourceName: "Complication/Utilitarian")

let complicationTemplate = CLKComplicationTemplateUtilitarianSmallFlat()
complicationTemplate.imageProvider = CLKImageProvider(onePieceImage: icon)
complicationTemplate.textProvider = textProvider
return complicationTemplate

case .extraLarge:

let icon = #imageLiteral(resourceName: "Complication/Extra Large")

let complicationTemplate = CLKComplicationTemplateExtraLargeSimpleImage()
complicationTemplate.imageProvider = CLKImageProvider(onePieceImage: icon)
return complicationTemplate

default:
return nil
}
}

complicationManifest.json 文件。

{
"supported complication families" : {
"3" : "B82ADE2C-045D-491D-87DD-C24148804480.json",
"6" : "A332202A-4B7B-49E0-83FB-DB398089E4FE.json",
"4" : "817476CB-1683-4604-A76D-2977236448AD.json",
"2" : "50AB27ED-0FA3-41AD-A3E7-CC9C62E48D82.json",
"0" : "DBE31877-7BB0-4671-B065-6FE00333929E.json",
"7" : "96966B70-AB8D-4DB3-AB64-AFDF1F09EB88.json"
},
"client ID" : "net.borisy.ProductDisplayName.watchkitapp.watchkitextension"
}

项目设置。

Xcode Complication Configuration

疑难解答。

  • 尝试重置模拟器。
  • 在真实设备和模拟器上都试过了。
  • Complication Bundle 通过拖动 gallery.ckcomplication 保存为“创建文件夹引用”
  • gallery.ckcomplication 位于根级别的项目中。与 .xcodeproj 同级别。

更新。

我添加了更多代码。我还将 ckcomplication.strings 添加到 Watch Extension Target。

再次阅读 Apple 指南后,我开始思考:

For example, MyBundleName.ckcomplication.

也许我们假设将生成的文件夹名称 gallery 重命名为包名称。我试过了。到目前为止没有运气。

最佳答案

我不确定您方法的其余部分是什么样子,但我遇到了同样的问题,直到我确定为我们支持的所有并发症类型添加了足够的信息。然后生成适当的 json 和图像文件。

使用空白文本提供程序(并且模板图像与复杂图像集相匹配)似乎很愚蠢,但这似乎是一种解决方法。

- (void)getLocalizableSampleTemplateForComplication:(CLKComplication *)complication
withHandler:(void(^)(CLKComplicationTemplate *complicationTemplate))handler {
// This method will be called once per supported complication,
// and the results will be cached
UIImage *templateImage = [UIImage imageNamed:@"template"];
CLKImageProvider *image =
[CLKImageProvider imageProviderWithOnePieceImage:templateImage];
CLKTextProvider *text = [CLKTextProvider textProviderWithFormat:@""];
CLKComplicationTemplate *complicationTemplate;

switch (complication.family) {
case CLKComplicationFamilyCircularSmall: {
CLKComplicationTemplateCircularSmallSimpleImage *small =
[[CLKComplicationTemplateCircularSmallSimpleImage alloc] init];
small.imageProvider = image;
complicationTemplate = small;
break;
}
case CLKComplicationFamilyExtraLarge: {
CLKComplicationTemplateExtraLargeSimpleImage *large =
[[CLKComplicationTemplateExtraLargeSimpleImage alloc] init];
large.imageProvider = image;
complicationTemplate = large;
break;
}
case CLKComplicationFamilyModularLarge: {
// Unexpected complication type.
break;
}
case CLKComplicationFamilyModularSmall: {
CLKComplicationTemplateModularSmallSimpleImage *small =
[[CLKComplicationTemplateModularSmallSimpleImage alloc] init];
small.imageProvider = image;
complicationTemplate = small;
break;
}
case CLKComplicationFamilyUtilitarianLarge: {
CLKComplicationTemplateUtilitarianLargeFlat *large =
[[CLKComplicationTemplateUtilitarianLargeFlat alloc] init];
large.imageProvider = image;
large.textProvider = text;
complicationTemplate = large;
break;
}
case CLKComplicationFamilyUtilitarianSmall: {
CLKComplicationTemplateUtilitarianSmallSquare *small =
[[CLKComplicationTemplateUtilitarianSmallSquare alloc] init];
small.imageProvider = image;
complicationTemplate = small;
break;
}
case CLKComplicationFamilyUtilitarianSmallFlat: {
CLKComplicationTemplateUtilitarianSmallFlat *small =
[[CLKComplicationTemplateUtilitarianSmallFlat alloc] init];
small.imageProvider = image;
small.textProvider = text;
complicationTemplate = small;
break;
}
}
handler(complicationTemplate);
}

这很老套,我认为正确的解决方案是提供真实的图像(和文本)数据,但这似乎可行。

关于swift - 复杂功能未出现在图库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41335087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com