Smart Stack widgets, error message

What does it mean?

Please adopt cont...

The error

The widget background view is missing. Please ensure that you have called the `containerBackground(for: .widget) {…}` modifier in your widget view.

I do use .containerBackground(Color.blue.gradient, for: .widget), but it's no longer working in Xocde beta 8

Answered by borisy in 764154022

This was caused by running watchOS extension target instead of the app target. I don't really need to debug widgets because the code is so simple, but if you have this issue, just run the app target for now. I also opened a radar FB13141297.

The issue is due to this error message

The widget background view is missing. Please ensure that you have called the `containerBackground(for: .widget) {…}` modifier in your widget view.

Hower I can see the background in SwiftUI preview.

Accepted Answer

This was caused by running watchOS extension target instead of the app target. I don't really need to debug widgets because the code is so simple, but if you have this issue, just run the app target for now. I also opened a radar FB13141297.

I have managed to fix this warning by providing the background for all families.

var body: some View {
    switch family {
    case ...
        // Return your custom widget here for families you support
    default:
       // Fallback for not supported families
       Image(systemName: "xmark.circle")
            .containerBackground(Color.black, for: .widget)
    }
}
Smart Stack widgets, error message
 
 
Q