0
votes

I'm including a Today extension with the next release of my iOS app. The content of the widget updates only when the user makes a specific change to the database managed by the containing app.

Is there a way to send some kind of signal from the containing app to the Today widget process to let it know that its data has been invalidated and that it should reload itself the next time the user pulls down the Notification Center?

1

1 Answers

1
votes

You don't need to update the widget yourself, iOS tries to update it periodically. Every time iOS does that, a function in your widget gets called. This is the function:

func widgetPerformUpdateWithCompletionHandler(completionHandler: ((NCUpdateResult) -> Void)!)

If your data has changed, then call

completionHandler(.NewData)

else, if your data hasn't changed, call

completionHandler(.NoData)

That's it! And don't make anything inside that function that needs a lot of time, because iOS may "kill" your widget then.