When I try to use an ip address instead of a hostname to tell an ios application in a simulator to talk to a local server the app hangs on the loading screen, waiting for a response from the server that never comes.
I'm new with Objective C but the code is using the AFNetowrking framework that's handling the request and the SCNetworkReachabilityFlags property is set differently for the ip address on the AFHTTPClient object.
The following properties of the AFHTTPClient object for ip address and hostname were captured during a debug.
<SCNetworkReachability 0xd26d8a0 [0x53b9ec8]>
{address = 127.0.0.1, flags = 0x00010002, if_index = 1}
<SCNetworkReachability 0xcf283f0 [0x53b9ec8]>
{name = localhost (server query active), flags = 0x80000000, if_index = 0}
In the startMonitoringNetworkReachability method within the AFHTTPClient.m class there is the following if statement that is triggered for the ip address but I don't know if it is the problem:
/* Network reachability monitoring does not establish a baseline for IP addresses as
it does for hostnames, so if the base URL host is an IP address, the initial
reachability callback is manually triggered.
*/
if (AFURLHostIsIPAddress(self.baseURL)) {
SCNetworkReachabilityFlags flags;
SCNetworkReachabilityGetFlags(self.networkReachability, &flags);
dispatch_async(dispatch_get_main_queue(), ^{
AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusForFlags(flags);
callback(status);
});
}
My question is what's causing the problem and how do I use an IP address as baseURL to connect to a server?