I’m using NSURLConnection with sendAsynchronousRequest method (and handing the data in block).
Using above method, I’m downloading a video file from server and saving locally in cache folder.
This is working fine if the URL is valid. If the URL is invalid (that is the video is not available at given URL), it is still saving a file with the file name that I’m giving. NSError is nil and NSData object is not nil. How can I check whether the URL is valid or catch the error if URL is not there?
I’m using NSURLConnection with sendAsynchronousRequest method (and handing the data in block). Using above
Share
Check the
NSURLResponsein the block, if it is an http request it is really anNSHTTPURLResponse. Check thestatusCodeto see the HTTP error. It may be a 404, 302, etc.Also check the returned data, convert it to a string and see if there is anything interesting there. Sometimes there is a redirect in the returned html.