Search code examples
ios16lockscreenwidget

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


I want the user to be able to tap on a lock-screen widget created by my app and deep link to my main app (eg, so that my main app can take some action) I have been able to do this with Home Widgets, but the same method does not work with the Lock Screen widgets in iOS 16.

Is this possible? Here is a code that works for Home Widgets:

                    Link(destination: myActionURL) {
                    Image("my_image").resizable(capInsets: EdgeInsets(), resizingMode: .stretch)

Solution

  • 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)