I'm trying to make a cron that runs every X time on the iOS system to send some data to the server.
I have read that there is no way to access a cron on a device that does not have a jailbreak. Researching a bit I found that the closest thing to a cron that can be done is to use UILocalNotification
or Background Fetch
in iOS 7, although with these methods you are at the mercy of the system.
I decided to try the Background Fetch option and followed this guide .
The problem I'm having is that it seems that it does not enter this method and it does not launch ever with the App open or in the background.
What I've tried
I have activated the Background Modes of the app by selecting the Background Fetch option as seen in the following photo:
The code I have in the AppDelegate is the following:
-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
NSDate *fetchStart = [NSDate date];
NSLog(@"Background Fetch: performFetchWithCompletionHandler");
Utilidades *util = [[Utilidades alloc]init];
BOOL conexion = [util testInternetConnection];
//Se comprueba si hay conexión a Internet
if (conexion) {
//Envio la información al servidor
completionHandler(UIBackgroundFetchResultNewData);
} else {
NSLog(@"Sin conexión. No se realiza nada");
completionHandler(UIBackgroundFetchResultFailed);
}
NSDate *fetchEnd = [NSDate date];
NSTimeInterval timeElapsed = [fetchEnd timeIntervalSinceDate:fetchStart];
NSLog(@"Background Fetch Duration: %f seconds", timeElapsed);
}
Does anyone know how to make it run every X interval regardless of whether the application is running or not? In which Can I be failing?