After updated to Xcode 15 and run my apps, all widgets including lock screen widgets appear this warning: WIDGET_BACKGROUND_API_ADOPTION_PROMPT, does anyone having same issue?
Replies
Same issue here. I have this warning even in the Widget Library Preview when adding a new Widget.
I suppose there is something (like a prompt?) is missing in the beta 1 but can't see any related issue in the release notes.
It seems to be related to our projets. I tried the Emoji Rangers Apple sample code and there is not this warning on the widgets.
So same issue here. I missed a log message in the console:
The widget background view is missing. Please ensure that you have called the `containerBackground(for: .widget) {…}` modifier in your widget view.
Just add the new .containerBackground(for:) in your widget view and it will resolve the issue.
https://developer.apple.com/videos/play/wwdc2023/10027?time=180
-
Thank you, this is very helpful
-
After updated to Xcode 15 and run my apps,there are three new example widgets on the preview interface,how to remove them
How are we supposed to keep our widgets also compatible with iOS 14-16 with this new containerBackground requirement? How can we conditionally apply a modifier based on iOS version?
-
Yeah, my solution:
var body: some View { …. { } .adoptableWidgetBackground(color) }
extension View { func adoptableWidgetBackground(_ color: Color) -> some View { if #available(iOS 17.0, *) { containerBackground(for: .widget) { color } } else { background(color) } } }
-
When I add this, I get an error in Xcode: Branches have mismatching types 'some View' (result of 'Self.containerBackground(for:alignment:content:)') and 'some View' (result of 'Self.background(_:alignment:)')
-
Yeah: add @ViewBuilder before func resolve this issue