0

Can we write background service in ios which will continuously run in background after some delay (e.g 1 min).

I have an application which fetch data after every minute i want to write background service for it.

independent of application running or not,though application is not in memory, service should continuously run after 1 minute.

I have written same service in android application but i don't know it is possible or not in ios.

Rajiv
  • 1,245
  • 14
  • 28

2 Answers2

0

No you can't, iOS decides when your app can fetch. check the "Background Fetch mode" in this article.

franck
  • 2,995
  • 3
  • 17
  • 28
0

Well, Actualy it depend on task what you want to perform. Main point is you cant perform any task in Background permanently. at the interval of time you need to request. You can perform few task in background like Downloading and etc. You need to use dispatch_async Something like in - (void)applicationDidEnterBackground:(UIApplication *)application

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    bgTask = [application beginBackgroundTaskWithName:@"MyTask" expirationHandler:^{
        // Clean up any unfinished task business by marking where you
        // stopped or ending the task outright.
        [application endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    }];

    // Start the long-running task and return immediately.
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        // Do the work associated with the task, preferably in chunks.

        [application endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    });
}

For more Detail like finite task , you can find on apple's document in below link.

BackgroundExecution

You can also get more help regarding background services from below link.

running-background-services-in-ios

Community
  • 1
  • 1
Badal Shah
  • 7,541
  • 2
  • 30
  • 65