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
I Get Nil When Using Nsdateformatter in Swift
How to Get Nsnumberformatter Currency Style from Isocurrencycodes
iOS 13.2 Message: Nehelper Sent Invalid Result Code [1] for Wi-Fi Information Request
Check Whether Time Falls Between Two Time iOS
Uiactivityviewcontroller Subject Not Working for Outlook
Fixing Low Fps in Swift Playground
Draw Polyline Using Google Maps in Custom View with Swift 3
Mkannotation Not Getting Selected in iOS5
Sprite Frame Animation Cocos2D 3.0
What Is The Purpose of Launch Images in an iOS Application
Selecting All The Items in UIcollectionview iOS, Even The Cells That Are Not Visible
Disable iOS Reachability Swipe Gesture in iOS Game
React Native 0.40.0: Rctbundleurlprovider.H" File Not Found - Appdelegate.M
Xcode Error Extra Info About Plist: Acl=<Not Found>
How to Upload Multiple Images in Multipart Using Alamofire