[英]I have added Widgetkit to my app but now crash on iOS 13 when the app starts on Xcode 12 beta
I have added WidgetKit to my app but on iOS 13 devices it crashes when the app starts with this error: dyld`__abort_with_payload我已将 WidgetKit 添加到我的应用程序中,但在 iOS 13 设备上,当应用程序以以下错误启动时它会崩溃: dyld`__abort_with_payload
The part of the code that causes the crash is this:导致崩溃的代码部分是这样的:
static func reloadTimelines () {
if #available(iOS 14, *) {
WidgetCenter.shared.reloadTimelines(ofKind: "com.myDomain.myApp.ProgressWidget")
}
}
I have tried other unsuccessful variations like this:我尝试过其他不成功的变体,例如:
@available(iOS 14, *)
static func reloadTimelines () {
WidgetCenter.shared.reloadTimelines(ofKind: "com.myDomain.myApp.ProgressWidget")
}
The project is in objective-c and I import that class in swift.该项目在objective-c中,我快速导入该类。
But without adding #import "myApp-Swift-h" anywhere, or using that class it keeps crashing.但是如果没有在任何地方添加 #import "myApp-Swift-h" 或者使用那个类,它就会一直崩溃。
Can someone tell me what I am doing wrong or what is happening?有人可以告诉我我做错了什么或发生了什么吗?
Thanks in advance.提前致谢。
Edit: I try this code on Xcode 11 and work!编辑:我在 Xcode 11 上尝试此代码并工作!
#if canImport(WidgetKit)
WidgetCenter.shared.reloadTimelines(ofKind: "com.literautas.StoryPlanner.ProgressWidget")
#endif
But it crashes on Xcode 12 beta 4但它在 Xcode 12 beta 4 上崩溃了
Edit 2: It also crashes on Xcode 12 beta 6编辑 2:它也会在 Xcode 12 beta 6 上崩溃
Another person (thank you, Mark) gave me the solution.另一个人(谢谢你,马克)给了我解决方案。 Marking the WidgetKit.framework as "optional" did the trick!
将 WidgetKit.framework 标记为“可选”就成功了!
For those who are still having issues.对于那些仍然有问题的人。 Try these changes.
尝试这些更改。
Make Optional Import进行可选导入
#if canImport(WidgetKit)
import WidgetKit
#endif
Check for iOS Version检查 iOS 版本
if #available(iOS 14, *) {
WidgetCenter.shared.reloadAllTimelines()
}
Last Step - Most Imp最后一步 - 最大的印象
Add WidgetKit to the Build Phase -> Link Libraries and make it optional将WidgetKit添加到Build Phase -> Link Libraries并使其成为可选
I was missing doing the last step and then the code started working in iOS 13 as well.我错过了最后一步,然后代码也开始在 iOS 13 中工作。
We had我们有
#if canImport(WidgetKit)
@available(iOS 14.0, *)
And the crash was still happening, apparently even on iOS 14.崩溃仍在发生,显然即使在 iOS 14 上也是如此。
We moved all WidgetCenter calls to a single file with all the measures and an additional one:我们将所有 WidgetCenter 调用移动到一个包含所有度量值和一个附加度量值的文件中:
NSClassFromString("WidgetKit.WidgetCenter")
For some reason, we can't explain yet, this is actually returning nil for some cases .出于某种原因,我们还不能解释,这实际上在某些情况下返回 nil 。 We prevented the crashes but in those cases, it means we can't really use the WidgetCenter API.
我们阻止了崩溃,但在这些情况下,这意味着我们无法真正使用 WidgetCenter API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.