Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

But without adding #import "myApp-Swift-h" anywhere, or using that class it keeps crashing.

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!

#if canImport(WidgetKit)
   WidgetCenter.shared.reloadTimelines(ofKind: "com.literautas.StoryPlanner.ProgressWidget")
#endif

But it crashes on Xcode 12 beta 4

Edit 2: It also crashes on Xcode 12 beta 6

like image 265
Tomeu Mascó Avatar asked Dec 17 '22 12:12

Tomeu Mascó


2 Answers

Another person (thank you, Mark) gave me the solution. Marking the WidgetKit.framework as "optional" did the trick!

like image 143
Tomeu Mascó Avatar answered Dec 24 '22 01:12

Tomeu Mascó


For those who are still having issues. Try these changes.

Make Optional Import

#if canImport(WidgetKit)
import WidgetKit
#endif

Check for iOS Version

if #available(iOS 14, *) {
     WidgetCenter.shared.reloadAllTimelines()
 }

Last Step - Most Imp

Add WidgetKit to the Build Phase -> Link Libraries and make it optional

I was missing doing the last step and then the code started working in iOS 13 as well.

like image 33
Ankit Saxena Avatar answered Dec 24 '22 00:12

Ankit Saxena