Widget Bundle: Widget removed from homescreen after random time

Environment:

  • Xcode 15.3.0.
  • MacOS 14.4.1 (23E224)
  • Depl. Target: iOS 17.2
  • Supported Destinations: iPhone
  • Notes: Using SwiftData. Shared code in the Persistency library.

Hello everyone,

I am writing here after really trying everything I can to understand what is going on.

I have a widget bundle composed by two different widgets, defined as following:

import WidgetKit
import SwiftUI
import SwiftData

@main
struct MyWidgetBundle: WidgetBundle {
    
    @WidgetBundleBuilder
    var body: some Widget {
        MyWidget()
        MylMediumWidget()
    }
}

They have 2 different providers (since they need different data).

The are then defined as following:

import SwiftUI
import WidgetKit
import Persistency
import SwiftData

struct MyMediumWidget: Widget {

    let kind: String = "MyStatus"
    
    var body: some WidgetConfiguration {
        StaticConfiguration(kind: kind, provider: MyEntryProvider()) { entry in
            MyMediumWidgetView(entry: entry)
                .containerBackground(Color.Theme.background, for: .widget)
        }
        .supportedFamilies([.systemMedium, .systemLarge])
        .configurationDisplayName("My Reminder Medium")
        .description("Bla bla bla")
    }
}

And

import WidgetKit
import SwiftUI
import Persistency

struct MyWidget: Widget {

    let kind: String = "MyStatus"
    
    var body: some WidgetConfiguration {
        StaticConfiguration(kind: kind, provider: SmallEntryProvider()) { entry in
            MyWidgetGroup(entry: entry)
                .containerBackground(Color.Theme.background, for: .widget)
        }
        .supportedFamilies([.systemSmall, .accessoryCircular])
        .configurationDisplayName("My Reminder Small")
        .description("Bla bla 2")
    }
}

struct ActiveMealWidgetGroup: View {
    
    var entry: SmallEntryProvider.Entry
    
    @Environment(\.widgetFamily) var family
    
    var body: some View {
        switch family {
        case .systemSmall:
            MySmallWidgetView(entry: entry)
        case .accessoryCircular:
            MyAcessoryCircularWidgetView(entry: entry)
        default:
            Text("Unsupported size")
        }
    }
}

Note: They belong to 1 single Widget Extension for iOS.

For some reason I have VERY strange behaviors in widgets with the following code. Example:

  1. When I insert the medium size, it is randomly removed from the home screen. For example, I add the small and the medium. After 3h, the medium is gone.
  2. If I try to add the widgets in mac os (readying from phone, the app is only for iOS), only the small appears. No medium and large are shown.
  3. If I try to compile the widget scheme selecting systemLarge in the xcode argument, I have an error saying: "Request widget family (systemLarge) is not supported by this widget kind (MyStatus)" UserInfo={NSLocalizedDescription=Request widget family (systemLarge) is not supported by this widget kind (MyStatus)}}

What is going on? Seems my widgets are really wrongly configured, but I can't see where the issue can be.

Hope someone can help me.

Best Regards