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

how can I use build URLCredential with 2 perm file?

I have one piece of python code that need to transfer into swift code. I see lots of example using URLSessionDelegate and URLCerdentital. I see the signure for URLCredential is .init(identity: <#T##SecIdentity#>, certificates: <#T##[Any]?#>,…
jacobcan118
  • 7,797
  • 12
  • 50
  • 95
0
votes
1 answer

RapidApi and Swift

I do not understand, how I can implement a RapidApi in a Swift Project, what am I doing wrong? import Foundation let headers = [ "x-rapidapi-host": "community-open-weather-map.p.rapidapi.com", "x-rapidapi-key": "[your rapidapi key]" ] let…
treenera
  • 19
  • 3
0
votes
2 answers

Limit API Calls to 40 per minute (Swift)

I have a limit of 40 URL Session calls to my API per minute. I have timed the number of calls in any 60s and when 40 calls have been reached I introduced sleep(x). Where x is 60 - seconds remaining before new minute start. This works fine and the…
Paul
  • 183
  • 1
  • 12
0
votes
2 answers

Using self as delegate in initializer for instance variable swift

I'm porting parts of an Objective-C framework to Swift, and I have an issue I can't think of how to fix. As part of one of the classes, I need to store a URLSession to access a remote API, and I would like to be able to store it as an instance…
beeselmane
  • 1,111
  • 8
  • 26
0
votes
1 answer

How to use POST request to Firebase Firestore from swift?

I would like to use the Firestore REST API from Swift, because I am using Siri Shortcut Intents, where I am not able to use the native SDK. What I have tried so far is to create an URLSession with "POST" httpmethod, but no luck. I have been able…
Viktor Maric
  • 443
  • 1
  • 4
  • 10
0
votes
2 answers

Stream Requests Uploads getting slow in iOS Background Session from iOS 15.x

I am working on an app which uses iOS NSURLSession background session to upload the data to the S3 server. From iOS 15.x, We have observed that transfer speed has become too slow (~10 kbps). Following is the configuration, I am using Create the…
gauravs
  • 19
  • 1
  • 4
0
votes
1 answer

How to determine Error response from Swift.Result and Enum

I created a method that uses Swift.Result to return an image and an Error from a URLSession. I also created an Enum for the errors. When a Swift.Result error is returned, how can I tell the difference between the 4 enums? fetchImage(with: url) {…
Lance Samaria
  • 17,576
  • 18
  • 108
  • 256
0
votes
1 answer

URLSEssion Does not send any response

I was trying to learn the basics of networking with openweather api. Implemented a very basic struct like this. protocol WeatherManagerDelegate { func didUpdateWeather(_ weatherManager : WeatherManager, weather : WeatherModel) func…
Ae Ri
  • 185
  • 1
  • 12
0
votes
0 answers

How to check if one of URLSession tasks returned an error and if so to stop code execution?

I need to make 2 API calls simultaneously. I have 2 URLs for the calls, and if one of the calls will return any error I want to stop all the code execution. How I tried to do it: I have a function called performRequest() with a completion block. I…
0
votes
1 answer

Obj-C POST JSON (body?)to endpoint problems

Using Postman on my Mac I have confirmed GET/POST works to my endpoint. On my iPad I am trying to do the same thing but only GET connects and returns data (just for testing). In Postman I have key of devices and value of…
malaki1974
  • 1,605
  • 3
  • 16
  • 32
0
votes
1 answer

How to add network fetch inside swift struct initializer

I'm trying to get data from an URL (1st network call), then make a 2nd network call to fetch image from the url in the first response, and present on tableview in swift. The json from 1st network call contains 3 strings: struct Item: Codable { …
RobotX
  • 208
  • 2
  • 15
0
votes
1 answer

Can't use URLSession with Swift on Watchkit

I have a problem when trying to fetch some data with swift on apple watch. When i try this code in Swift Playground it works well but when I put it in an WatchOS app it shows me this error : Error Domain=NSURLErrorDomain Code=-1202 "The certificate…
MaxBrt18
  • 63
  • 1
  • 9
0
votes
0 answers

Timeout error when post public key string with URLSession

I am creating a rsa key pair and send the public key to my api. But the post request fails with Timeout error. Following is my function for the request: func perform(reqData: Data, with completion: @escaping (T?) -> Void) { var…
Panks
  • 565
  • 1
  • 7
  • 20
0
votes
3 answers

Is it possible to download any file app suspension or quiet mode in iOS?

I'm seeking a mechanism to download any file (video, audio) not only for app background but also for app suspension or quit mode. It is like an android youtube application, background download. That means OS should handle the download process. I'll…
AMIT
  • 906
  • 1
  • 8
  • 20
0
votes
0 answers

How to properly cancel and restart an URLSessionDataTask Swift

This is my request funtion: func receiptValidation(completion: @escaping(_ isPurchaseSchemeActive: Bool, _ error: Error?) -> ()) { let receiptFileURL = Bundle.main.appStoreReceiptURL guard let receiptData = try? Data(contentsOf:…
Tulon
  • 4,011
  • 6
  • 36
  • 56