1

I was trying to open a URL session for a chunked response, I am able to achieve this by setting backgroundSessionConfigurationWithIdentifier in NSURLSessionConfiguration object. The URL session still runs if app goes to background, but the session terminates once I quit the app by swapping out from multitask view. Is there a way to restrict quitting the app till didFinishDownloadingToURL delegate called.

I have achieved the similar functionality in my android app using a native thread (boost thread reside in a .so called by UI thru JNI) which does not terminate if the UI is swapped out from the multi task view. Is there a way to achieve same in IOS app?

regards, Birajendu

Toseef Khilji
  • 17,192
  • 12
  • 80
  • 121
Birajendu
  • 29
  • 5

1 Answers1

0

According to NSURLSession guide background session task executes in different process (not thread). And finished even if initiator app was killed. You can reassign to bg task when relaunch app.

In both iOS and OS X, when the user relaunches your app, your app should immediately create background configuration objects with the same identifiers as any sessions that had outstanding tasks when your app was last running, then create a session for each of those configuration objects. These new sessions are similarly automatically reassociated with ongoing background activity.

Not sure is it possible to get the task result if your app was terminate during bg session and session completed before you restart app.

Ilia
  • 1,434
  • 15
  • 22
  • Thanks for the reply, Yes NSURLSession completes the download task if the app terminates. But my requirement is little bit beyond that. I need to post local notification once the download completes, I am not getting completion handler in case the user quit the app. – Birajendu Oct 01 '15 at 16:04
  • @Birajendu You can extend app life time after it transition to background (but not killed by swiping in multitask menu) using this APIs: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/#//apple_ref/occ/instm/UIApplication/beginBackgroundTaskWithExpirationHandler: – Ilia Oct 02 '15 at 05:13
  • thanks for your suggestion, but that is not solving my purpose. My purpose is to open a always ON http connection to server and keep getting chunked data, every time I receive data I want to fire a local notification. – Birajendu Oct 07 '15 at 06:23