Core data and Today Widget

Hello I have an application that calculates the usage of your internet connection (read data transfer, roaming data, wifi...). I'm trying to update it with a Widget. The first part of the app, reading the values from the database and showing them on the widget works perfect, but the values are updated only when the host app is open. I want that the widget save data to the database too, I have read a lot about context conflicts and tried to solve it, but nothing work for me. Here you have my code:

TodayViewController.h

//
//  TodayViewController.h
//  WidgetCC
//
//  Created by Óscar García Pérez on 25/3/15.
//

#import <UIKit/UIKit.h>
#import "Limits.h"
#import <CoreData/CoreData.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <ifaddrs.h>
#include <net/if_dl.h>
#include "DataRegister.h"
#include "DataRegisterDetailDTO.h"
//#import "NewCalculateCostData.h"
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>
#import <CoreLocation/CoreLocation.h>
#include "Alarms.h"
#include "User.h"
#import "SqliteSequence.h"
#import "NewDataRegister.h"
#import "CallRegister.h"
#import "LatestDataRegister.h"


@interface TodayViewController : UIViewController //<CLLocationManagerDelegate>

@property (readonly, strong, nonatomic) NSManagedObjectContext* managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel* managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator* persistentStoreCoordinator;
@property (nonatomic, retain) NSTimer* silenceTimer;
//@property (nonatomic, strong) CLLocationManager* locationManager;
@property (atomic) Boolean callActive;
@property (atomic) Boolean roamingStatus;
@property (nonatomic, strong) CLLocation* lastLocation;
@property (nonatomic, retain) NSString* currentMcc;
@property (nonatomic, retain) NSString* currentCountry;

@end

TodayViewController.m

[link removed]

Almost all these methods come from AppDelegate:

AppDelegate.m

[link removed]

Thanks in advance.

Upvotes: 0

Views: 131

Answers (1)

Finally I removed the option of save records from widget. What I do is update visually the widget with local data, and let all the "save to database" work to the host app.

Upvotes: 1

Related Questions