Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Buttons to a iOS 14 Widget

I'm trying to add buttons to a widget having family type ".systemLarge". I want to execute some code without opening the app.

Anyone knows how to do that?

For example the Shortcuts App Widget includes buttons you can tap to execute a shortcut without opening the app.

like image 349
Spriter Avatar asked Jun 30 '20 20:06

Spriter


2 Answers

Widgets are read only. The Shortcuts app is an exception.

https://developer.apple.com/documentation/widgetkit/creating-a-widget-extension

Widgets present read-only information and don’t support interactive elements such as scrolling elements or switches. WidgetKit omits interactive elements when rendering a widget’s content.

like image 118
DanubePM Avatar answered Nov 04 '22 18:11

DanubePM


You can add Link controls on medium and large size widgets to get a button like behavior.

This won't allow you to create interactive widgets, which change their content by clicking elements inside the widgets. But you will be able to tell which "link" was clicked based on the widgetUrl provided when your app gets activated through the widget.

See the chapter Respond to User Interactions here: https://developer.apple.com/documentation/widgetkit/creating-a-widget-extension

like image 34
Thyraz Avatar answered Nov 04 '22 20:11

Thyraz