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
1
vote
2 answers

NSURLSession is not downloading full webpage

I'm currently attempting to download a webpage using a NSURLSession in order to retrieve a status update on the download progress. Unfortunately, after downloading the webpage, when I go to load the webpage, there are visual issues (missing images,…
TheCodingArt
  • 3,436
  • 4
  • 30
  • 53
1
vote
1 answer

iOS: authentication and token expiration using NSURLSession

I have an application with fairly simple authorization/authentication and need a bit of help on how to handle the authorization life cycle. Here's the jist of it: The user enters their credentials to log in and the server responds with a token and…
Matt
  • 1,415
  • 2
  • 15
  • 23
1
vote
1 answer

How to download multiples file in background and update corresponding progressview

I am using NSURLSession to download files in background ..I have seen this link and it is working fine .But i have to download multiple files ,Like the image i uploaded. How to achieve this ,any advise would be highly appreciated.
Sishu
  • 1,510
  • 1
  • 21
  • 48
1
vote
1 answer

How to update JSON File from web server

I have my local data in json file like : { "locations": [ { "title": "The Pump Room", "place": "Bath", "latitude": 51.38131, "longitude": -2.35959, "information": "The Pump Room Restaurant in Bath is one of the…
1
vote
2 answers

NSURLSession - execute two requests and parse two responses, but still block main thread

I want to execute two requests to my remote server and get and parse two response asynchronously, but still block the main thread until both of two processes are done. Here's my code in AppDelegate.m's application: didFinishLaunchingWithOptions:…
Blaszard
  • 30,954
  • 51
  • 153
  • 233
1
vote
3 answers

Is there a performance loss to receiving NSData and transforming it into a UIImage versus getting a UIImage directly?

When I download an image I usually use dataWithContentsOfURL: asynchronously, but it always returns a UIImage. Is all data that comes over the network initially a form of NSData? Or does downloading it as NSData and then converting it to a UIImage…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
1
vote
2 answers

NSURLSession error: bad URL, works in the browser

I am fetching posts from facebook with the below session and get back 'bad url' error. When I take the same URL and open it in a browser, I get back proper JSON full of posts. What is the problem with my session? Thanks. - (void)loadFacebookPosts { …
Martin Koles
  • 5,177
  • 8
  • 39
  • 59
1
vote
2 answers

Can I make iOS 7 send pictures in the background when network connection is established?

I am building an app for iOS 7 that allows the user to select pictures and upload these to a server. In a perfect world the user would choose the pictures, press upload and be able to close the app. I looked in to NSURLSession to establish this but…
FreekHelm
  • 23
  • 2
1
vote
1 answer

AFNetworking 2 and background tasks

I have a question about AFNetworking 2 and background downloads/uploads thanks to the new iOS7 NSURLSession background requests Is this automatically handled by my AFHTTPRequestOperationManager ? Does it automatically set my requests'session to…
Noé Malzieu
  • 2,530
  • 3
  • 22
  • 27
1
vote
1 answer

Uploading a file with NSURLSession

I am trying to upload a file with the following method: - (void)uploadWithTarget:(NSString *)url andFileData:(NSData *)file andMD5Checksum:(NSString *)checksum { NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration…
davidOhara
  • 1,008
  • 5
  • 17
  • 39
1
vote
2 answers

What am I doing wrong with NSURLSession that's not allowing me to POST to this API?

I made a quick test project and through this in the viewDidLoad: NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *urlSession = [NSURLSession…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
1
vote
3 answers

How can I restrict all networking requests to a Wi-Fi connection with AFNetworking 2.0?

I have a rather odd question. I want to know if it's possible to block any requests (current and future) using AFNetworking 2.0. My app needs to do something like this: if the user is not on a wifi connection -> block any requests that the app may…
alex
  • 957
  • 2
  • 9
  • 16
1
vote
1 answer

Returning directory listing with PHP

I am using the following to return the listing of all text files on my server. echo json_encode(glob("*.{txt}", GLOB_BRACE)); The issue I am having is when I execute this php file from my app, with only one text file in the directory, it returns…
1
vote
1 answer

How to use restclient dropbox API with NSURLSessionDownloadTask to download files

Problem: i want to download a file from my dropbox account and use quick look to visualize it. First Solution: 1) use Dropbox API restClient: [[self restClient] loadFile:fullpath intoPath:finalpath]; 2) Once downloaded use QLPreviewController to…
dev-dom
  • 369
  • 2
  • 11
1
vote
1 answer

iOS - Background transfer Tasks don't match

I'm trying to upload my iOS photo's from the camera roll to an external server via a background fetch call. To accomodate this, i loop through ALAssetsLibrary in the background fetch to look for new photos. When new photos are found or all photo's…
Wouter
  • 71
  • 4