How to use a WidgetBundle in @available(iOS ver, *)

I try Control Widget I check API availability like this

don't work WidgetBundleBuilder.buildBlock() so i use ControlWidgetConfigurationBuilder.buildBlock ! but it didn't work too

what should i do ?

Answered by simonfromhelix in 790706022

Would something like this format help?

import WidgetKit
import SwiftUI

@main
struct AppWidgets {
    // Combine widgets in this way to prevent crashes.
    static func main() {
        if #available(iOSApplicationExtension 18.0, *) {
            WidgetsBundle18.main()
        } else {
            WidgetsBundle17.main()
        }
    }
}

@available(iOSApplicationExtension 18.0, *)
struct WidgetsBundle18: WidgetBundle {
    var body: some Widget {
        NewWidget()
    }
}

struct WidgetsBundle17: WidgetBundle {
    var body: some Widget {
        OldWidget()
    }
}
Accepted Answer

Would something like this format help?

import WidgetKit
import SwiftUI

@main
struct AppWidgets {
    // Combine widgets in this way to prevent crashes.
    static func main() {
        if #available(iOSApplicationExtension 18.0, *) {
            WidgetsBundle18.main()
        } else {
            WidgetsBundle17.main()
        }
    }
}

@available(iOSApplicationExtension 18.0, *)
struct WidgetsBundle18: WidgetBundle {
    var body: some Widget {
        NewWidget()
    }
}

struct WidgetsBundle17: WidgetBundle {
    var body: some Widget {
        OldWidget()
    }
}
How to use a WidgetBundle in @available(iOS ver, *)
 
 
Q