Questions tagged [nsurlsession]

NSURLSession is the API for HTTP connections introduced in iOS 7 and OS X 10.9.

The class NSURLSession was introduced to Apple's Foundation.framework in iOS 7 and OS X 10.9.

A NSURLSession object can be considered a group of related data transfer tasks. A response may be received and can be handled via a block statement or delegate methods. NSURLSession provides status and progress properties, of which support canceling, resuming, or suspending tasks, and resuming suspended, canceled, or failed downloads.


Types of Sessions

NSURLSession can support three different types of sessions, which is determined by the configuration object used to initialize the session object.

  • Default Sessions
  • Ephemeral Sessions
  • Background Sessions

Types of Tasks

There are three types of tasks, the last two (Download & Upload) of which support background use.

  • Data Tasks - Send and receive data via a NSData object
  • Download Tasks - Retrieves data in the form of a file
  • Upload Tasks - Sends data, most typically in the form of a file

Related tags to explore:

Adapted from Apple's URL Loading System Programming Guide > NSURLSession.

2479 questions
0
votes
1 answer

URLsession .failure crash the app because error is nil

I am trying to throw an error when I have status code 500. when I hit this line completion(.failure(error!)) I have "Fatal error: Unexpectedly found nil while unwrapping an Optional value" is they are a problem with my URL session functional? func…
developer16
  • 195
  • 12
0
votes
1 answer

What‘s the best practices of NSURLSession?

Subscribe my app first: Most scenes use AFNetworking, a small part of scenes use NSURLSession.sharedSession or create a new NSURLSession. Using one URLProtocol instance to handle almost all requests, and at the end of -startLoading function, using…
YUI
  • 1
  • 2
0
votes
1 answer

How can I decode custom Error with Combine?

The API I'm making calls to can return JSON containing error message. How can I tell Combine to try and decode this custom error if I'm expecting another Decodable object to be returned on successful request? My code currently looks like this: …
Adam
  • 1,776
  • 1
  • 17
  • 28
0
votes
1 answer

Fetch data in background NSURLSession

I have used [NSURLSession sharedSession] to get data from server.While getting the data if the app moves to background and after sometime if it comes to foreground I get "Connection was lost" error. So I implemented getting data in background and…
Honey
  • 2,840
  • 11
  • 37
  • 71
0
votes
0 answers

iOS - Objective-C: application crash on iOS 10 after libraries upgrade

I have an older Objective-C application that I upgraded recently in order to add new functionalities. I'm using now AFNetworking version 4.0. All is working now even in the newest version of iOS except on iOS 10. When I run it on the simulator, the…
Ne AS
  • 1,490
  • 3
  • 26
  • 58
0
votes
0 answers

mobile number issue when sending post request to register

Here is the problem when I click to the button it gives me response from server saying Mobile number is not valid I think because phone number must include + which refers to the key of the country and I don't know if my body in the code support (+)…
0
votes
1 answer

Switched from sendSynchronousRequest deprecated to NSURLSession ,now app does not launch first activity

Previous code [NSURLConnection sendSynchronousRequest:request returningResponse:&response error: NULL]; return ([response statusCode] == 200) ? YES : NO; Code using now +(BOOL)isConnectNetwork{ NSString *urlString = @"http://www.google.com/"; NSURL…
Kofi Sammie
  • 3,237
  • 1
  • 17
  • 17
0
votes
0 answers

NSURLSession with delegate is not working on main thread

I want that NSURLSession's delegation is called on the main thread. When I passed [NSOperationQueue mainQueue] to delegateQueue, the delegation was not called. @interface NSURLSessionTests : XCTestCase { …
0
votes
0 answers

Swift : Track group of API calls to show progress bar

I have collection view with 6 cells - each cell makes 3-4 different API calls . I want to show collective progress bar below navigation bar . How to keep track of api calls to generate progress from them ? PS: API calls don't have any download or…
Akash Shindhe
  • 558
  • 4
  • 16
0
votes
1 answer

Swift/URLSession returns a different public key than OpenSSL

I have this code (can be run in a playground): import UIKit import CryptoKit let url: URL = URL(string: "https://apple.com")! final class SSLExtractor: NSObject, URLSessionDelegate { private var session: URLSession! init(url: URL) { …
Antzi
  • 12,831
  • 7
  • 48
  • 74
0
votes
0 answers

how to get JSON data from login without alamofire

I am able login, but don't get any data from listpeserta. I want to get user's name etc func onlinecheckin(){ self.password.resignFirstResponder() let password1 = password.text; if let user1 = user.text { // To trim the…
dante
  • 5
  • 4
0
votes
1 answer

How to retrieve array of images from array of url swift

I'm trying to retrieve images from array of url.. I have this function that do the same as I won't but it doesn't work so I tried to use URLSession but didn't know how exactly to make it >> func downloadImages(imageUrls: [String], completion:…
NANA
  • 7
  • 5
0
votes
0 answers

HttpClient object does not works second time on Xamarin.iOS

I use HttpClient object for PostAsync. I need to add BackgroundSessionConfiguration for iOS while I am creating HttpClient object. So I changed my code like this: var configuration = NSUrlSessionConfiguration.CreateBackgroundSessionConfiguration…
0
votes
2 answers

Correct way to pass NSError from URLSession

I have Network layer class, which has method with URL request. Seems like this: - (void)networkRequestWithError:(NSError *__strong *)responseError andCompletion:(void (^)(NSData*))completion { NSURL *url = ... …
0
votes
1 answer

iOS 13 NSURLSession websocket does not use TLS 1.3

I'm trying to use TLS 1.3 on my websocket connection that is based on NSURLSession webSocketTaskWithRequest:. Strangely it does not ask the server for TLS 1.3. But when I use pretty much same code for HTTPS request, it uses TLS 1.3 for its request.…
REALFREE
  • 4,378
  • 7
  • 40
  • 73
1 2 3
99
100