4

A)If NSURLSession runs task in background in iOS7,Has Apple integrated internally Queue in NSURLSession?How it works in secondary thread and also in App suspended Mode?

B)What is the difference between NSURLSession and NSoperationqueue?

C)If NSURLSession is the replacement of NSURLCOnnection, Can we integrate NSURLSession into NSOPerationqueue?

D)Are both same?

E)Can we do the same thing in NSURLSession as in NSoperationQueue?

f)is there any time limit to do task in background after closing application? because iOS7 does 2 min while ios6 does 10 min?

G) Tutorial says under section Configuration and Limitation,NSURLSessionDataTasks are not supported in background sessions at all, and you should only use these tasks for short-lived, small requests, not for downloads or uploads.some tutorials are telling there is no time limit, we can download or upload data,the size may be whatever..Please explain more on this? If NSURLSession is the relplacement of NSUrlconnection ,Which one is the best in all situations?What is the future of NSUrlconnection?

senthilM
  • 9,414
  • 18
  • 77
  • 140

1 Answers1

10

A) Yes, NSURLSession has its operation queue which maintains all the session tasks delegates in queue.

B) No, NSURLSession and NSOperationQueue has nothing for comparison. In fact, NSURLSession itself has a property of NSOperationQueue. NSURLSession is a replacement-API for NSURLConnection not NSOperationQueue.

C) There is no need of explicitly integrating it to NSOperationQueue. Every NSURLSession object has its own NSOperationQueue to perform its tasks concurrently.

D) Refer A,B,C

E) Again, this is a wrong comparison, NSURLSession is not replacement or equivalent for NSOperationQueue, it is replacement for NSURLConnection.

F) NSURLSession enables to use iOS7 background fetch mode with a background session configuration

[NSURLSessionConfiguration backgroundSessionConfiguration:@"identifier"];

If your question is about general background task execution, in iOS7 you can perform a task in background for 180.0 seconds. But for the background fetch request, you can fetch only for 30.0 seconds

G) Yes, Background fetch is basically designed for downloading/uploading stream of data at regular intervals managed by OS. OS provides the timeframe for your app periodically based on the available system resources. If your app cannot complete the download in 30.0 seconds, with NSURLSession the same task can be resumed next time.

NSURLSession is evolving and it has new priority request model also in iOS8, so I would suggest you to go with NSURLSession. It is asynchronous, it supports authentication handling, it supports separate cache storage, it supports periodic downloads and lot more.

Anil Kumar
  • 679
  • 1
  • 6
  • 18
  • anil, If i implement NSURLsession,Can I upload data continuously for 1/2 n hour without any time construction after closing app? suppose if upload is stopped after 180 seconds,will it be resumed automatically without opening application manually to foreground? – senthilM Jun 23 '14 at 05:50
  • @JeffWood You can resume the download task using - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes. But for the upload tasks, apple did not give any resume handler(even in iOS 8). – Anil Kumar Jun 24 '14 at 16:06
  • No, from iOS 7 you can perform the background tasks only for a period of 180.0 seconds, after that time iOS will kill your app with crash log as "Application is running in background beyond permitted time". But still you can monitor the remaining background time to handle your logic using [UIApplication sharedApplication].backgroundTimeRemaining . This time limit is not just specific to NSURLSession (Background fetch is an exception here as it is allowed only for 30.0 seconds). – Anil Kumar Jun 25 '14 at 16:14
  • anil , http://www.appcoda.com/background-transfer-service-ios7/ this link says there is no time limit like 180 secs in ios7,Did you read this? How can this tutorial say, No time limitation for upload and download in backgoround? – senthilM Jun 30 '14 at 05:14
  • @JeffWood Appcoda tutorial is a complete coverage on how we can pause and resume the background tasks. And also it talks about background transfer service which directly implies a multiple 30 second transfers controlled solely by iOS. And regarding the 180 seconds time limit for any background task, it can be observed by monitoring backgroundTimeRemaining property of shared App delegate, This value starts from 180.0 immediately when tha app moves to background. When it becomes 0.0 iOS terminates the app immediately with a crash report( if app is performing any operations beyond) – Anil Kumar Jun 30 '14 at 19:34
  • https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:performFetchWithCompletionHandler: This link explains in detail about the background transfer time limit of 30 secs – Anil Kumar Jun 30 '14 at 19:37
  • Earlier upto iOS6 the permitted background time is 600 seconds (i.e., 10 mins) which can be observed by using [UIApplication sharedApplication].backgroundTimeRemaining. But from iOS7 this value got changed to 180.0 seconds and sadly it is not documented. Still iOS behaves as expected by killing the app when it reaches this time. – Anil Kumar Jun 30 '14 at 19:43
  • How kindle ios app downloads data in background continuously in ios ? please refer http://stackoverflow.com/questions/4704037/download-data-in-background-with-ios4?lq=1 – senthilM Jul 01 '14 at 05:59