Senthilkumar
Senthilkumar

Reputation: 2481

Frequent time interval background fetch made

I have developed two different applications

  1. App1 - With Healthkit enabled.
  2. App2 - ionic application

App1 task : Read data from healthkit which is store in the server.

App2 task : Retrieve the stored data from server and display.

I started App2 from App1 using openURLScheme. So App1 running on the background mode and also It should be continued more than 3 mins to an hour.

I tried following Scenario:

bgTask = self.applicationUI!.beginBackgroundTaskWithName("MyTask", expirationHandler: { () -> Void in

        self.applicationUI!.endBackgroundTask(self.bgTask!)

        self.bgTask = UIBackgroundTaskInvalid;
    })

    self.bgTask = UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler({ () -> Void in
        self.monitorInBackground()
    })

I get error : permittedBackgroundDuration: 180.000000 reason: finishTask

extent background process for next 3 minute (After IOS 7 introduce. before IOS 7, the process execution time was 10 minute).

Note :

I hope it can be feasible using APNS silent notification. But I expected better solution other than the APNS.

Upvotes: 2

Views: 900

Answers (1)

Stephen Darlington
Stephen Darlington

Reputation: 52565

Apple has a good section on background execution in their documentation.

The two ways of doing this are a silent notification (as you suggest) and background fetch.

The "pro" of using a silent notification is that you can control when it happens fairly precisely as long as your user is online. (Which they probably have to be to access the server anyway.) But, yes, it adds a lot of complexity.

Background fetch works nicely, but you don't get much control over when it happens. This may or may not be a problem, depending on what your app does.

Other options that might work include background audio, location updates and VoIP, but they might get you rejected.

Just running a background task won't work -- that's designed for finishing off tasks rather than keeping them running for a long time.

Upvotes: 2

Related Questions