我使用“pod install”安装 AFNetworking 2.0,并使用 App.xcworkspace。使用 AFNetworking 2.0,我成功发送了 POST 请求,但在可达性方面我遇到了问题。我需要监视套接字何时打开和关闭,我的代码不起作用,我忘记了什么?
// Check server socket available
struct sockaddr_in serverAddr;
serverAddr.sin_family = AF_INET;
serverAddr.sin_len = sizeof(serverAddr);
serverAddr.sin_port = htons(80);
serverAddr.sin_addr.s_addr = inet_addr("192.168.1.108");
AFNetworkReachabilityManager *reachability = [AFNetworkReachabilityManager managerForAddress:&serverAddr];
[reachability setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusNotReachable:
NSLog(@"No Internet Connection");
break;
case AFNetworkReachabilityStatusReachableViaWiFi:
NSLog(@"WIFI");
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
NSLog(@"3G");
break;
default:
NSLog(@"Unknown network status");
break;
}
}];
[reachability startMonitoring];