0

I have requirement to update application containing viewcontroller from todayextension widget view controller when app is in either in background/foreground state. Lets assume.

  1. App containing viewcontroller contains list of information. Next press on home button app goes to background state.
  2. Now open widget and show list of information as shown in app containing viewcontroller in TodayExtensionViewcontroller.
  3. If you update any information in TodayExtensionViewController same information I want to replicate in App containing viewcontroller when app goes from background to foreground state.
Raginmari
  • 2,291
  • 23
  • 21
Rajesh
  • 124
  • 9
  • Use `App Group` and `UserDefaults`. Check this [link](https://stackoverflow.com/questions/24015506/communicating-and-persisting-data-between-apps-with-app-groups) – Ryan Oct 25 '17 at 19:04

1 Answers1

0

Your app and Today extension have to be able to share data.

First of all, you have to add the "App Group" capability to the App IDs of both your app and your Today extension so that they can access shared data.

The easiest way to share data is to use shared user defaults, but it is also possible to share a persistent Core Data store, for example.

Every time your app enters the foreground, it should check if the shared data has changed (or just reload its data from the shared store) so that changes made in the widget take effect.

Every time the user changes data in your app (or at least before the app becomes "inactive"), the app should update the shared data so that the widget is up to date.

This guide by Apple is a good starting point. Moreover, there are lots of good tutorials available that explain "data sharing" in much more detail.

Raginmari
  • 2,291
  • 23
  • 21