To bring my widgets to iPad lock screen, i need to detect my widget that has a background to display different contents, watch the wwdc 23 video it tells we can use .showsWidgetContainerBackground environment to apply that goal, but the problem is this code wouldn't compile because .showsWidgetContainerBackground only available in iOS 17
@available(iOS 14.0, *)
struct MyWidgetView: View
{
@Environment(\.showsWidgetContainerBackground) var showsBackground
var body: some View {
...
}
}
So, my solution is use a environment wrapper, like this:
@available(iOS 17.0, *)
struct EnvironmentWrapper: View
{
@Environment(\.showsWidgetContainerBackground) var showsWidgetContainerBackground
var body: some View {
VStack(alignment: .leading) {
Text("Wrapper Has Background: \(showsWidgetContainerBackground ? "YES" : "NO")")
}
}
}
extension View
{
var showsWidgetContainerBackground: Bool {
if #available(iOS 17.0, *)
{
return EnvironmentWrapper().showsWidgetContainerBackground
}
else
{
return true
}
}
}
But it didn't work, this is the example:
@available(iOS 17.0, *)
struct EnvironmentWrapper: View
{
@Environment(\.showsWidgetContainerBackground) var showsWidgetContainerBackground
var body: some View {
VStack(alignment: .leading) {
Text("Wrapper has background: \(showsWidgetContainerBackground ? "YES" : "NO")")
}
}
}
@available(iOS 17.0, *)
struct ExampleView: View
{
@Environment(\.showsWidgetContainerBackground) var showsBackground
var body: some View {
VStack(alignment: .leading) {
Text("Read from self: \(showsBackground ? "YES" : "NO")")
EnvironmentWrapper()
Text("Read from wrapper: \(EnvironmentWrapper().showsWidgetContainerBackground ? "YES" : "NO")")
}
.font(.system(size: 12, weight: .medium))
}
}
As you can see, if i read it directly from self, it works, but if i read from outside, it always return true
i also try to load a view first in the wrapper, but it didn't work either
func getShowsBackground() -> Bool
{
let _ = body
return showsWidgetContainerBackground
}
Post
Replies
Boosts
Views
Activity
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?
Hello, sometimes if I use NSMetadataQuery to obervse my file changes on macOS, it crash for this reason, its odd and i have no clue for this problem becuse in my code I never get results using index, anyone help? thanks!
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[_NSMetadataQueryResultArray objectAtIndex:]: index (251625) out of bounds (251625)'
terminating with uncaught exception of type NSException
abort() called
if you turned Tap to Wake on your iPhone 13 Pro( not sure iPhone 13 has the same issue ), when press side button to wake screen, you can see the brightness is acting not normal, it goes very low brightness at first then transition to normal brightness odd, but if you turn Tap to Wake on, this issue is gone. My iPhone 12 is not have the issue.
Everybody meeting some situation here? It totally make my computer uneasy to control.
In the Big Sur Apple has remove Today Extension and replace it to Widgets, so Today Extension is no longer exist.
Today I try to add a Widget Extension in my macOS app: File -> New -> Target -> macOS, but there is no Widget Extension there, and I tried to add an iOS Widget Extension but it does not embed in my macOS app so not working.
What the hack? do I have to rebuild a whole new cross platform app to archive that gold or something what? does anybody is meeting some problem here or macOS just being abandon??