When I try to use the ip address instead of the host name to let the iOS application in the simulator talk to the local server, the application freezes on the loading screen, waiting for a response from the server that never appears.
I am new to Objective-C, but the code uses the AFNetowrking structure that processes the request, and the SCNetworkReachabilityFlags property is set differently for the ip address of the AFHTTPClient object.
During debugging, the following AFHTTPClient object objects were captured for the ip address and host name.
<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 in the AFHTTPClient.m class, there is the following if statement that runs for the ip address, but I do not know if this is a problem:
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 causes the problem and how can I use the IP address as baseURL to connect to the server?
source share