How to Add a Lock Screen Widget (Requiring iOS 16) and Still Support iOS 15

How can we add a Lock Screen Widget (requiring iOS 16) and still support iOS 15?

I think this should work. Simply return an EmptyWidgetConfiguration in case the widget is not supported.

struct SomeWidgetBundle: WidgetBundle {
@WidgetBundleBuilder
var body: some Widget {
AlwaysAvailableWidget()
LockScreenWidget()
}
}

struct LockScreenWidget: Widget {
var body: some WidgetConfiguration {
if #available(iOSApplicationExtension 16.0, *) {
return StaticConfiguration(
kind: "some.kind",
provider: LockScreenWidgetTimelineProvider()
) { provider in
Text("Some view")
}
.configurationDisplayName("Some display name")
.description("Some description")
.supportedFamilies([.accessoryCircular])
} else {
return EmptyWidgetConfiguration()
}
}
}

This did not work before Xcode 14, but SE-0360 is already implemented and you can do this now.

iOS 16 Lock-screen Widget: can we add a deep link to the widget

I was able to do this using widgetURL. In the app delegate catch the url using func applicationHandle(url: URL) and do the action based on the url.

            VStack(spacing: 0) {
Text("\(String(carName))").font(.system(size: 10)).fontWeight(.bold).minimumScaleFactor(0.4)
Image("action").resizable(capInsets: EdgeInsets(), resizingMode: .stretch)
.aspectRatio(contentMode: .fit).foregroundColor(entry.widgetTextColor)
}
.widgetURL(url)

Widgets not showing in iOS 15 or earlier from Xcode 14

Had same problem, managed to fix with removal of all .accessoryCorner cases from WidgetFamily switches across several files. Hope it helps you too.



Related Topics



Leave a reply



Submit