Tay*_*son 8 ios swift widgetkit
我正在为 iOS 10+ 构建一个 iOS 应用程序。该应用程序在 Debug 配置中构建良好,但在 Release 中无法编译引用WidgetCenter.
Cannot find WidgetCenter in scope即使我正在导入WidgetKit并可选择嵌入框架,它也会输出错误。
import Foundation
import WidgetKit
class MyWidgetCenter: NSObject {
@available(iOS 14, *)
func reloadTimelines(_ kind: String) {
// this line causes error: cannot find 'WidgetCenter' in scope
WidgetCenter.shared.reloadTimelines(ofKind: kind)
}
@available(iOS 14, *)
func reloadAllTimelines() {
// this line causes error: cannot find 'WidgetCenter' in scope
WidgetCenter.shared.reloadAllTimelines()
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:当我设置Build Active Architecture Only标志时,它在发布配置中为模拟器和我连接的设备(iPhone XR)构建良好。只有在为多个架构构建时,它才无法编译。是否存在WidgetKit我没有考虑的架构限制?
Tay*_*son 19
我相信 WidgetKit 应该支持该armv7架构,但是它无法编译WidgetCenterfor 的用法armv7。
我的解决方法是包装WidgetCenter语句,只支持我需要的架构之外armv7
class MyWidgetCenter: NSObject {
@available(iOS 14, *)
func reloadTimelines(_ kind: String) {
#if arch(arm64) || arch(i386) || arch(x86_64)
WidgetCenter.shared.reloadTimelines(ofKind: kind)
#endif
}
@available(iOS 14, *)
func reloadAllTimelines() {
#if arch(arm64) || arch(i386) || arch(x86_64)
WidgetCenter.shared.reloadAllTimelines()
#endif
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2852 次 |
| 最近记录: |