Getting Started With Widgets | raywenderlich.com

Hello! I’m a new-ish iOS developer tasked with adding a widget to an existing codebase (which happens to be all UIKit), and this tutorial has been enormously helpful – thank you for providing such clear explanations! I just navigated through the whole tutorial, and one thing I’m not clear on is whether the app needs to continuously run in the background in order to refresh the widget. Can Emitron still provide its widget with data when closed because it caches it locally? Or is a widget somehow able to force the app to make an API call even when it’s not open?

In our app, the in-app content that will also be presented in the widget is currently only fetched on inital app load (though I’m planning to add a periodic background refresh to this, for users who – unlike me – don’t force-close their apps when not in use). The json feed I’m hitting only updates once a day, and I think many of our users currently interact with the app less than that. If the widget can’t force the API call in the app to occur, it seems like I ought to put a separate API call into the widget itself and then pass the data to the app.

Thank you in advance for any clarification, and I’d appreciate any suggestions you might have on where else to look for information that I might have missed!

hi Jessica! I’m glad my tutorial was helpful. I’m writing a book chapter about widgets, this time for a much simpler app than Emitron. I plan to call the app’s fetchContents method from the widget if the data array is empty. This code is shared between app and widget so I think it will work even when the app isn’t running at all.

This article mentions some methods that might be useful, in sections named Background Network Handler and Requesting A Reload. The first is for the widget; the second is for the app to tell the widget to request a reload.

let me know how you go?

TimelineIntervalIntent is autogenerated file upon TimelineInterval intentdefinition file.
To be properly generated you should create intentdefinition file on the whole project and try to build the whole project first.

1 Like

This tutorial is more than six months old so questions regarding it are no longer supported. Thank you!