Could any one please tell me what is the real advantage gained by using NSURLSessionTask inside NSOperation while making http network calls in iOS? We can get the abstraction by wrapping NSURLSessionTask inside any other plain custom class e.g APIRequest. What is the real motto behind using NSOperation for network calls? Thanks in advance.
Advantage of wrapping NSURLSessionTask inside iOS NSOperations
140 Views Asked by Arjuna At
1
There are 1 best solutions below
Related Questions in IOS
- Overlapping UICollectionView in storyboard
- Cannot pod spec lint because of undeclared type errors
- Is the transactionReceipt data present in dataWithContentsOfURL?
- UIWebView Screen Fitting Issue
- ZXingObjC encoding issues
- iOS: None of the valid provisioning profiles allowed the specific entitlements
- How to hide "Now playing url" in control center
- CloudKit: Preventing Duplicate Records
- Slow performance on ipad erasing image
- Swift code with multiple NSDateFormatter - optimization
- iOS 8.3 Safari crashes on input type=file
- TTTTimeIntervalFormatter always returns strings in English
- How do I add multiple in app purchases in Swift Spritekit?
- Setup code for xibs in iOS. -awakFromNb:
- iOS Voice Over only reads out the title of any alert views
Related Questions in NSURLSESSION
- Using NSURLSession from a Swift command line program
- NSURLSession/NSURLConnection HTTP load failed on iOS 9
- How to send HTTPS POST request in swift using NSURLSession
- Can someone find the error and verify my Swift NSURLSession code?
- UI Slow to Update *ONLY* If Called In Response To Change Occurring in NSURLSessionUploadTask Completion Block
- Resuming tasks using NSURLSession when app removed from background or on device reboot
- URLSession:didBecomeInvalidWithError: - should completion handler be called?
- I am having trouble parsing JSON that is returned from the NSURL session. What am I doing wrong?
- NSHTTPURLResponse Status Code 200 in Airplane Mode
- NSURLSession ignoring NSURLSessionConfiguration Cache Policy
- Is There A Neat Way to Attach a Completion Block to an NSURLSessionDataDelegate Callback in Swift?
- Swift dataTaskWithRequest completion block not executed
- Multiple NSURLSessions Causing UITableView Problems
- Cancel NSURLSession if user taps twice in swift iOS
- NSURLSession background transfer timeout not fired
Related Questions in NSOPERATIONQUEUE
- iOS7: Multi-UITableview rendering lag
- NSOperationQueue NSOperation USER_INITIATED crash
- Asynchronous request running slowly - iOS
- NSOperation & NSOperationQueue Cancellation
- Xcode 6.3 - Crash on Archive, NSOperationQueue
- How can I download datas from multiple URL in concurrency mode?
- Can NSOperation have a lower qualityOfService than NSOperationQueue?
- Downloading data from a number of urls in background thread using NSOperationQueue synchronously
- Should I use operation queue for this complete scenario?
- Combine AFHTTPRequestOperation and NSBlockOperation (iOS)?
- Replace asynchronous requests with synchronous requests in background thread in iOS?
- NSOperation wait until asynchronous block executes
- iOS Swift - How to reference a NSOperationQueue in an extension to cancel existing operations?
- NSOperationQueue block updates UI before previous task finishes
- Queueing with dispatch
Related Questions in NSOPERATION
- Implementing tasks that can be canceled in Bolts Framework (BFTask)
- NSOperationQueue NSOperation USER_INITIATED crash
- NSOperation & NSOperationQueue Cancellation
- Multiple KVO Keys: Why call willChangeValueForKey: twice before didChangeValueForKey:?
- How can I download datas from multiple URL in concurrency mode?
- Should I use operation queue for this complete scenario?
- How to Print Natural Numbers Sequentially but in 2 different threads Objective-C
- applicationDidEnterBackground is not waiting till method execution is completed
- Pass method to run on NSURLConnection's connectionDidFinishLoading
- Combine AFHTTPRequestOperation and NSBlockOperation (iOS)?
- Replace asynchronous requests with synchronous requests in background thread in iOS?
- NSOperation wait until asynchronous block executes
- Core Data fault on frequent data updating?
- Is [NSOperationQueue mainQueue] a serial queue?
- Cancelling an NSOperation from another NSOperation
Related Questions in NSURLSESSIONTASK
- Completion Handler of an NSURLSessionTask does not run
- iPhone NSURLSessionTask does not work on iOS 6
- What is difference between NSURLSessionDataTask vs NSURLSessionDownloadTask
- Why did writing with URLSessionStreamTask time out?
- Can a URLSessionStreamTask be used for both reading and writing?
- Swift : Track group of API calls to show progress bar
- Does NSURLSessionTask keep taskIdentifier after session reconnection?
- NSURLSessionTask completionTask never get call in main queue using GCD
- Returning directory listing with PHP
- Measuring total response time for NSURLSession's dataTaskWithRequest
- File downloader Using NSURLSessionTask downloadTask
- Cancel Downloadtask pending
- How to prevent resume the duplicate NSURLSessionTask
- Using NSURLSessionDataTask, can I resume downloading a file, even if user comes back after quitting an App?
- When i am trying to send data in post method NSUrlSessionTask i am getting this error?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
My first inclination would be to say "none whatsoever", but after thinking about it a bit more, that's probably slightly too glib.
In general, if your app already uses NSOperation for performing other tasks, it may be useful to have your network operations just be another special type of operation, so that you can kind of manage them in the same way. Of course, if you do that, you almost certainly shouldn't use NSOperation directly; instead, use a custom subclass of NSOperation that actually knows how to cancel the network operation when you call its cancel method. Using the NSOperation class as-is could be even worse than useless, if misused.
The best explanation I have for why it is so common is historical. Apparently, a lot of programmers mistakenly believed that wrapping synchronous NSURLConnection requests inside of NSOperation objects gave them a way to cancel those requests. In reality, all it did was prevent the app from ever getting the data from the request, but the request continued until its completion. Unfortunately, in updating that code to use NSURLSession, that legacy baggage was often brought along for the ride, and is likely just as problematic now as it was then.
As others have mentioned in comments, you could also ostensibly use operations to allow pending requests to continue after your app gets backgrounded, but in general, doing so is probably a mistake. After all:
So really, the advantages to using a custom NSOperation subclass are the same as the advantages of using an NSOperation for anything else in your app — no more, no less.