如何判断iphone是否联网

+(BOOL)isNetworkReachable{ 

// Create zero addy struct sockaddr_in zeroAddress; 

bzero(&zeroAddress, sizeof(zeroAddress));
zeroAddress.sin_len = sizeof(zeroAddress);
zeroAddress.sin_family = AF_INET;

// Recover reachability flags 

SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddres(NULL, (struct sockaddr *)&zeroAddress);

SCNetworkReachabilityFlags flags;

 BOOL didRetrieveFlags = SCNetworkReachabilityGetFlag(defaultRouteReachability, &flags); 

CFRelease(defaultRouteReachability);

 if (!didRetrieveFlags) {
                  return NO;
               }

}

 

你可能感兴趣的:(iPhone)