2

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.

Kumar KL
  • 15,315
  • 9
  • 38
  • 60
Senthilkumar
  • 2,471
  • 4
  • 30
  • 50
  • I am also working on same kind of app where background fetch is required, but didn't find solution to maintain socket connection to server in background mode for more than 10 minutes. This is somehow possible with the help of VOIP's but I am not sure apple will approve this. – Vijay Sanghavi Dec 11 '15 at 13:33
  • @VijaySanghavi can you please share the code to achieve( till 10 mins) – Senthilkumar Dec 11 '15 at 13:58
  • You had 10 minutes prior to (iOS 7. After iOS 7 the background execution time is 3 minutes. You should use a different approach to your app. long term execution in the background with frequent server updates will drain battery and user cellular data allowances. You can use background fetch mode without push notification but your execution will only be every few hours. – Paulw11 Dec 11 '15 at 14:08
  • @Paulw11 Could you please list it. What are the different approach available. – Senthilkumar Dec 11 '15 at 14:15
  • pardon please, my mistake @Senthilkumar that was 3 minutes not 10 minutes – Vijay Sanghavi Dec 11 '15 at 14:22

1 Answers1

2

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.

Stephen Darlington
  • 51,577
  • 12
  • 107
  • 152