Implementing Dynamic Island support - Generic parameter 'Expanded' could not be inferred

I'm following Displaying live data with Live Activities and adding support for the Dynamic Island in an app with an existing widgets extension. However, I'm unable too get it to build

import SwiftUI
import WidgetKit


@main
struct PizzaDeliveryActivityWidget: Widget {
    var body: some WidgetConfiguration {
        ActivityConfiguration(for: PizzaDeliveryAttributes.self) { context in
            // Create the presentation that appears on the Lock Screen and as a
            // banner on the Home Screen of devices that don't support the
            // Dynamic Island.
            // ...
        } dynamicIsland: { context in
            // Create the presentations that appear in the Dynamic Island.
            // ...
        }
    }
}

as I get the errors

Generic parameter 'Expanded' could not be inferred

and

Result builder 'DynamicIslandExpandedContentBuilder' does not implement any 'buildBlock' or a combination of 'buildPartialBlock(first:)' and 'buildPartialBlock(accumulated:next:)' with sufficient availability for this call site

This is even if I supply a dynamicIsland closure of

            DynamicIsland {
                EmptyView()
            } compactLeading: {
                EmptyView()
            } compactTrailing: {
                EmptyView()
            } minimal: {
                EmptyView()
            }

What am I missing? My project's minimum deployment target is iOS 16.1.

According to the documentation, the argument expanded in DynamicIsland should implement DynamicIslandExpandedContentBuilder, instead of @ViewBuilder like the remaining others. So, I suggest you implement something like the following snippet:

DynamicIsland {
                // Create the expanded presentation.
                DynamicIslandExpandedRegion(.leading) {
                    EmptyView()
                }
                
                DynamicIslandExpandedRegion(.trailing) {
                    EmptyView()
                }
                
                DynamicIslandExpandedRegion(.bottom) {
                    EmptyView()
                }
            } compactLeading: {
                // Create the compact leading presentation.
                EmptyView()
            } compactTrailing: {
                // Create the compact trailing presentation.
                EmptyView()
            } minimal: {
                // Create the minimal presentation.
                EmptyView()
            }
}

I hope this helps you.

@available(iOS 16.1, *)

Try putting this above the struct.

For me this issue started to appear when I took down the iOS minimum deployment of my extension to 16.2 instead of 18.0.

I fixed it by adding @available(iOS 18.0, *) above all my #Preview:

@available(iOS 18.0, *)
#Preview("DI compact", as: .dynamicIsland(.compact), using: BackgroundRecordingAttributes.preview) {
    BackgroundRecordingLiveActivity()
} contentStates: {
    BackgroundRecordingAttributes.ContentState(isAudioOnly: true)
    BackgroundRecordingAttributes.ContentState(isAudioOnly: false)
}
Implementing Dynamic Island support - Generic parameter 'Expanded' could not be inferred
 
 
Q