colincameron
colincameron

Reputation: 2703

dataWithContentsOfURL and HTTP 302 redirects

How does [NSData dataWithContentsOfURL:] deal with 302 redirects?

I am requesting an MP3 file from a server by passing the URL of a PHP page which will check the user-agent and redirect to the MP3 file on a different server.

Upvotes: 2

Views: 1403

Answers (2)

viral
viral

Reputation: 4208

Write your loadImageInBackground function that contains [NSData dataWithContentsOfURL:] and run it in a background thread, like this:

[self performSelectorInBackground:@selector(loadImageInBackground:) withObject:nil];

This will not make synchronous network connection (hence will not freeze the UI).

Upvotes: 1

NeoNacho
NeoNacho

Reputation: 680

Never use [NSData dataWithContentsOfURL:] in a real app. It makes a synchronous network connection and your app will be killed by the OS if that doesn't finish quickly enough.

Stick to NSURLConnectionDataDelegate or use [NSURLConnection sendAsynchronousRequest:queue:completionHandler:.

Upvotes: 2

Related Questions