简体   繁体   English

我已将 Widgetkit 添加到我的应用程序中,但现在当应用程序在 Xcode 12 beta 上启动时在 iOS 13 上崩溃

[英]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 optionalWidgetKit添加到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 WidgetKit as optional in our main target和 WidgetKit 在我们的主要目标中是可选的

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.

相关问题 StoreKit 测试应用内购买 Xcode 12 beta 和 iOS 13 或更低版本 - StoreKit Testing In-App Purchases Xcode 12 beta & iOS 13 or below 如何在打开应用程序时修复iOS 13 beta应用程序崩溃? - How to fix iOS 13 beta app crash upon opening the app? UILabel导致应用程序在添加到视图时崩溃(仅限Xcode 6和iOS 8) - UILabel causes app to crash when added to view (Xcode 6 and iOS 8 only) 应用卡在带有Xcode 11 beta的iOS 13 beta模拟器上,但在带有Xcode 10的iOS 13 beta模拟器上运行良好 - App stuck on iOS 13 beta simulator with Xcode 11 beta but working fine on iOS 13 beta simulator with Xcode 10 从Xcode 10和iOS 12开始的Fabric Answer崩溃iOS应用 - Fabric Answer crash iOS app on start with Xcode 10 and iOS 12 使用 Xcode 13 构建后,应用程序在 iOS 12 及更低版本上崩溃 - App crashes on iOS 12 and below after building with Xcode 13 在 iPhone 应用程序启动之前,我必须等待 1 分钟,使用 Xcode 12 - I have to wait 1 minute, before iPhone app starts, using Xcode 12 我可以为 Xcode 11 beta 5 下载 iOS 13 beta 6 模拟器吗? - Can I download iOS 13 beta 6 simulator for Xcode 11 beta 5? 将Xcode 6 Beta,iOS 7应用程序发布到App Store - Release Xcode 6 Beta, iOS 7 app to App Store iOS 13 应用程序在后台使用 sinch 时调用包崩溃 - iOS 13 callkit crash when app in background using sinch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM