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
142 views Asked by Arjuna At
1
There are 1 answers
Related Questions in IOS
- URLSession requesting JSON array from server not working
- Incorrect display of LinearGradientBrush in IOS
- Module not found when building flutter app for IOS
- How to share metadata of an audio url file to a WhatsApp conversation with friends
- Occasional crash at NSURLSessionDataTask dataTaskWithRequest:completionHandler:
- Expo Deep linking on iOS is not working (because of Google sign-in?)
- On iOS, the keyboard does not offer a 6-character SMS code
- Hi, there is an error happened when I build my flutter app, after I'm installing firebase packages occurs that error
- The copy/paste functionalities don't work only on iOS in the Flutter app
- Hide LiveActivityIntent Button from Shortcuts App
- While Running Github Actions Pipeline: No Signing Certificate "iOS Development" found: No "iOS Development" signing certificate matching team ID
- Actionable notification api call not working in background
- Accessibility : Full keyboard access with scroll view in swiftui
- There is a problem with the request entity - You are not allowed to create 'iOS' profile with App ID 'XXXX'
- I am getting "binding has not yet been initialized" error when trying to connect firebase with flutter
Related Questions in NSURLSESSION
- How to embed client certificate into react native iOS app
- How to client SSL certificate for iOS app for React native project?
- Get webpage content with URLSession returns 403
- How can I read session variables directly in Objective-C for my iOS application?
- NSURLSessionDownloadTask results in 404 status when server issues a redirect
- .NET MAUI on iOS: Background NSUrlSession fails on Simulator
- How to run code in the background on iOS? Not sure which methodology makes sense
- NSURLSessionWebSocketDelegate delegates not being called iOS Objective c
- Where to set com.apple.application-identifier entitlement for background URLSession?
- Is it possible to change defaultSessionConfiguration of NSURLSessionConfiguration?
- `canInitWithRequest` not called in Xcode 15
- How to use URLSession to decide ignoreSSL from another class?
- Objective C POST call not executing NSURLSession
- Swift URLSession returns incorrect amount of bytes on request
- URLSession.didReceiveChallenge : how to ignore one specific certificate check on server-side authentication
Related Questions in NSOPERATIONQUEUE
- Does iOS OperationQueue have the same features of Android WorkManager (persistent, multiple tries, ability to see queue and status, network)?
- How to make sure that OperationQueue tasks are always getting executed on background(global) thread in swift?
- Why does my BlockOperation continue after I add it to an OperationQueue?
- How to interrupt Thread.sleep. Alternatives?
- how many operations NSOperationQueue can cache
- How to use OperationQueue to handle URLSessions for an image downloader
- Is DispatchQueue using RunLoop?
- Is there a way to enforce serial scheduling of async/await calls similar to a GCD serial queue?
- how to do blocking `dispatch_sync` using `NSOperationQueue`
- Swift 5.5 Concurrency: how to serialize async Tasks to replace an OperationQueue with maxConcurrentOperationCount = 1?
- iOS concurrent: how to use OperationQueue instead of barrier?
- How to schedule a NSOperation to the head of queue and let all other operations waiting for it?
- NSOperation Queue waitUntilAllOperationsAreFinished causes NSOperation instance deinit late
- Swift Multiple async web service response handler
- Serial API Calls in Objective C
Related Questions in NSOPERATION
- NSOperation with a delay - is it async or sync?
- Why does my BlockOperation continue after I add it to an OperationQueue?
- how many operations NSOperationQueue can cache
- How to schedule a NSOperation to the head of queue and let all other operations waiting for it?
- NSOperation Queue waitUntilAllOperationsAreFinished causes NSOperation instance deinit late
- How to perform all delay operations right away with NSOperation or GCD?
- Using Operations to manage imbalances between function calls
- Crashing at queue.sync { self._state }
- Can NSBlockOperation cancel itself while executing, thus canceling dependent NSOperations?
- Do you need to use URLSession's dataTask(with: URL) inside of an Operation class's main() method?
- Operation queuePriority not working as expected
- Alternatives to GCD to run code with a delay under SwiftUI
- (NS)Operation KVO dependencies
- App crash : NSInvalidArgumentException - Operation is already enqueued on a queue
- How to cancel specific Operation from OperationQueue in swift
Related Questions in NSURLSESSIONTASK
- Swift : Track group of API calls to show progress bar
- How to call custom method right before sessionTask resume in Alamofire
- Task created in a session that has been invalidated
- What happens when I call URLSessionTask's task.cancel()?
- Execute swift nsurlsession Tasks in serial order
- Advantage of wrapping NSURLSessionTask inside iOS NSOperations
- Can a URLSessionStreamTask be used for both reading and writing?
- Why did writing with URLSessionStreamTask time out?
- Is there any solution to pause NSURLSessionTask when iPhone goes to sleep and resume when iPhone becomes active
- Cancel Downloadtask pending
- File downloader Using NSURLSessionTask downloadTask
- NSURLSessionTask Never Calls Back When WiFi Off
- NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802 in iOS10, 2017
- How to wait for all tasks of an NSURLSession to complete?
- NSURLSessionTaskPriority seems to be ignored?
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?
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)
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.