我想在我的应用程序中添加一个超大的小部件作为 iOS 15 的支持系列。
WidgetConfiguration 的简化代码如下:
var body: some WidgetConfiguration {
IntentConfiguration(
kind: "Widget",
intent: SelectProjectIntent.self,
provider: Provider()
) {
entry in
ProgressWidgetEntryView(entry: entry)
}
.configurationDisplayName("Title")
.description("Description")
.supportedFamilies([.systemSmall, .systemMedium, .systemLarge, .systemExtraLarge])
}
显然我不能简单地添加额外的大,因为出现以下错误: 'systemExtraLarge' 仅适用于 iOS 15.0 或更高版本的应用程序扩展
但是做一个 XCode 建议的快速简单的可用性检查我得到一个错误和几个警告。这是代码:
var body: some WidgetConfiguration {
if #available(iOSApplicationExtension 15.0, *) {
IntentConfiguration(
kind: "Widget",
intent: SelectProjectIntent.self,
provider: Provider()
) {
entry in
ProgressWidgetEntryView(entry: entry)
}
.configurationDisplayName("Title")
.description("Description")
.supportedFamilies([.systemSmall, .systemMedium, .systemLarge, .systemExtraLarge])
} else {
IntentConfiguration(
kind: "Widget",
intent: SelectProjectIntent.self,
provider: Provider()
) {
entry in
ProgressWidgetEntryView(entry: entry)
}
.configurationDisplayName("Title")
.description("Description")
.supportedFamilies([.systemSmall, .systemMedium, .systemLarge])
}
}
错误是:函数声明了一个不透明的返回类型,但它的主体中没有返回语句来推断基础类型。
和两个警告:调用 'supportedFamilies' 的结果是未使用的。
有人可以向我解释为什么我会收到此错误以及如何修复它以便我可以保留 iOS 14 的小部件并为 iOS 15 添加 systemExtraLarge?
我在 macOS Monterey 版本 12.0 beta (21A5304g) 上使用 XCode 版本 13.0 beta 5
提前致谢。