I created a today extension for my iOS App. My app is fetching new datas in background and saving it into a shared database in the app group.
How I can make (if it's possible) the extension to update it's view when background fetches of the main app are performed ? If it's not possible, how I can make something equivalent (like regularly updating the extension to check for new datas in the shared database).
You can use shared NSUserDefaults and observer it.
In your app:
After you update database, execute the below:
NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.yourcompany.sharedDefaults"];
[userDefaults setObject:[NSDate date] forKey:@"updatedDate"];
[userDefaults synchronize];
In your Today Widget:
add a observer in viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(userDefaultsDidChange:)
name:NSUserDefaultsDidChangeNotification
object:nil];
then
- (void)userDefaultsDidChange:(NSNotification *)notification {
// check updatedDate and update widget UI
}
refer: http://www.glimsoft.com/06/28/ios-8-today-extension-tutorial/
The system create the ViewController every time, but your singleton-instance in your today widget code keep living during a long period.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With