Widget does not show up in search widget menu after .contentMarginsDisabled() in ios16

Hi, I'm playing with the new xcode 15 beta and am trying to solve the extra paddings around the widget by adding .contentMarginsDisabled() at the end as instructed by https://developer.apple.com/videos/play/wwdc2023/10027/

        IntentConfiguration(...)
                           ...
        .contentMarginsDisabled()
    }

it works fine for ios17 and actually fixed my extra padding problem, but on ios16 the app is not shown in the search widget menu anymore, anyone ran into the same issue?

Answered by amjiang in 758406022

checking

if #available(iOS 17.0, *)

then apply the .contentMarginsDisabled() worked for me

tried

var body: some WidgetConfiguration {
        if UIDevice.current.systemVersion.components(separatedBy: ".").first!.convertToInt! > 16 {
            return IntentConfiguration(kind: self.kind,
                                       intent: testIntent.self,
                                provider: testProvider()) { entry in
                testEntryView(entry: entry)
                    .frame(maxWidth: .infinity, maxHeight: .infinity)
                    .background(Color(.widgetBackground))
            }
            .configurationDisplayName(Localized("test") + ": " + Localized("test"))
            .description(Localized("test"))
            .supportedFamilies([.systemMedium])
            .contentMarginsDisabled()
        } else {
            return IntentConfiguration(kind: self.kind,
                                intent: testIntent.self,
                                provider: testProvider()) { entry in
                testEntryView(entry: entry)
                    .frame(maxWidth: .infinity, maxHeight: .infinity)
                    .background(Color(.widgetBackground))
            }
            .configurationDisplayName(Localized("test") + ": " + Localized("test"))
            .description(Localized("test"))
            .supportedFamilies([.systemMedium])
        }
        
    }

but got an error Function declares an opaque return type 'some WidgetConfiguration', but the return statements in its body do not have matching underlying types which is odd, this is not unlike the first approach but it won't recognize the body after .contentMarginsDisabled(), removing it fix the error

Same issue. Any solutions?

Accepted Answer

checking

if #available(iOS 17.0, *)

then apply the .contentMarginsDisabled() worked for me

Widget does not show up in search widget menu after .contentMarginsDisabled() in ios16
 
 
Q