WidgetKit: How to add deep link on iOS Widget?

Widget in iOS is massive update by Apple. Today we will discuss about the deep link on widget.

As per apple suggestions small widget have single tap target, medium and large widget can have multiple tap targets. For Example, a widget with multiple photos can have different tap targets to perform action on the specific photo.

Apple suggested to avoid offering so many targets that people have trouble tapping the one they want.

Let see how we can add it by code…

WidgetURL

.widgetURL(_ url: URL?) will make your whole widget clickable and will deep link to the specified URL. By default, clicking on a widget will open your app on whichever screen it was on.

For Example:

Link

Link(destination: URL) to wrap some content into a clickable deep link.

Note: Link will only work in systemMedium and systemLarge, for deep linking from a systemSmall widget, you’ll need to use widgetURL

For Example:

Conclusion

So many things are there to explore in iOS 14 and macOS Big Sur. If I get time, I will keep posted!

I am posting tweets/retweets about iOS everyday.

I hope you learned something. If you did, feel free to share this article with a friend or on social media. Let me know if you have any questions, comments or feedback – either via Twitter or email.

Stay Safe At Home. Learn Something New. Share To The World.
Happy Coding 🙂