Trying to build up simple function to get internet status, but getting leaks every time I call this function:
+ (BOOL) connectionStatus
{
BOOL retVal = NO;
const char *hostName = [@"google.com"
cStringUsingEncoding:NSASCIIStringEncoding];
SCNetworkReachabilityRef reach = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, hostName); // Attempt to ping google.com
SCNetworkConnectionFlags flags;
SCNetworkReachabilityGetFlags(reach, &flags); // Store reachability flags in the variable, flags.
if(kSCNetworkReachabilityFlagsReachable & flags) {
// Can be reached using current connection.
}
if(kSCNetworkReachabilityFlagsConnectionAutomatic & flags) {
// Can be reached using current connection, but a connection must be established. (Any traffic to the specific node will initiate the connection)
}
if(kSCNetworkReachabilityFlagsIsWWAN & flags) {
// Can be reached via the carrier network
} else {
// Cannot be reached using the carrier network
}
if((kSCNetworkReachabilityFlagsReachable & flags) && !(kSCNetworkReachabilityFlagsIsWWAN & flags)) {
// Cannot be reached using the carrier network, but it can be reached. (Therefore the device is using wifi)
retVal = YES;
} else if (kSCNetworkReachabilityFlagsIsWWAN & flags) {
// Using the carrier network
retVal = YES;
} else {
// No connection available.
}
return retVal;
}
Instruments shows leaks and always point as responsible frame SCNetworkReachabilityGetFlags and SCNetworkReachabilityGetFlags from SystemConfiguration . Any idea?