Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline."

When I try to connect to soundcloud using below code:

// Create the request.
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://soundcloud.com/api"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10.0];

// Create url connection and fire request
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];

While I get below error:

Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={NSUnderlyingError=0x14cfccae0 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "The Internet connection appears to be offline." UserInfo={NSErrorFailingURLStringKey=https://soundcloud.com/api, NSErrorFailingURLKey=https://soundcloud.com/api, kCFStreamErrorCodeKey=50, kCFStreamErrorDomainKey=1, NSLocalizedDescription=The Internet connection appears to be offline.}}, NSErrorFailingURLStringKey=https://soundcloud.com/api, NSErrorFailingURLKey=https://soundcloud.com/api, kCFStreamErrorDomainKey=1, kCFStreamErrorCodeKey=50, NSLocalizedDescription=The Internet connection appears to be offline.}

The Key is: I am running it on my iPhone, the network is 4G. The code is actually working well when I am using other network through Wifi.

like image 582
James Avatar asked Feb 22 '16 08:02

James


2 Answers

The reason is the 4G network turned off for the app on my iPhone, not sure when and why I did it though.

like image 119
James Avatar answered Sep 29 '22 18:09

James


i found the solution its because you set timeoutInterval:10.0 in

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://soundcloud.com/api"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10.0];

and response didn't get within this time, so all you need to exceed this time or you can also remove this interval

like image 22
Mahesh Sehajpal Avatar answered Sep 29 '22 17:09

Mahesh Sehajpal