0

I am trying to run the process in background thread . I want that process to finish in 60 secs and start running again.No matter application is in foreground or background. I don't know how to implement and where to implement it.I'm using ios7.In that process I'm also taking location updates.

I read about the background tasks, but it wasn't giving proper idea of the process. Can someone provide me with good source or link?

Aruna M
  • 386
  • 3
  • 12

2 Answers2

0

There is no such api given by ios for background process unlike android which use service for that.You can use timer for continuos background process .Also there is dispatch_async ,selector in background for efficient background processing.

Hope this helps.

shubham jain
  • 156
  • 1
  • 9
  • Ok fine.I will implement that using dispatch_async ,selector in background but when app enters background what to do. please tell me – Aruna M Mar 31 '14 at 06:22
0

you can use something like this for background processing,but remember apple has put restriction of 10-15 min to complete the processing.

UIApplication*    app = [UIApplication sharedApplication];
task = [app beginBackgroundTaskWithExpirationHandler:^{
        [app endBackgroundTask:task];
        task = 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.
        NSLog(@"Started background task timeremaining = %f", [app backgroundTimeRemaining]);
        if (connectedToNetwork) {
            // do work son...
        }

        [app endBackgroundTask:task];
        task = UIBackgroundTaskInvalid;
    });

Also you can check the following :

**BOOL backgroundSupported = NO;

if ([device respondsToSelector:@selector(isMultitaskingSupported)])

   backgroundSupported = device.multitaskingSupported;**
rene
  • 41,474
  • 78
  • 114
  • 152
shubham jain
  • 156
  • 1
  • 9
  • It is not a long-running task.task should finish in 60secs and starts again. It should run continuously in foreground and background i.e.for every 60 secs task should finish and starts again.please help me with that. – Aruna M Mar 31 '14 at 06:40
  • You need to check first whether the app is in background or foreground ,if in background then put the above code and if in foreground you can use whatever you feel like.Exp:Timer,selector thread,GCD. – shubham jain Mar 31 '14 at 07:14
  • then how to run that process continuously not just for 10 or 15 mins. – Aruna M Mar 31 '14 at 07:35
  • In the background ,you can not do processing more then 10-15 min.Apple restrict you to do that. – shubham jain Mar 31 '14 at 09:51