From fffa02425af59759e3a47401b3c7d2eb6790571b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Berg?= Date: Wed, 24 Mar 2010 09:20:37 +0100 Subject: [PATCH] SCNetworkCheckReachabilityByName will be deprecated anyways, so replace it with the docs example which will work on any OS version from 10.3. Modified-by: Nathan Kinsinger Released the target to stop memory leak. --- PBWebController.m | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/PBWebController.m b/PBWebController.m index d185593..27b672c 100644 --- a/PBWebController.m +++ b/PBWebController.m @@ -110,8 +110,14 @@ - (BOOL) isReachable:(NSString *)hostname { - SCNetworkConnectionFlags flags; - if (!SCNetworkCheckReachabilityByName([hostname cStringUsingEncoding:NSASCIIStringEncoding], &flags)) + SCNetworkReachabilityRef target; + SCNetworkConnectionFlags flags = 0; + Boolean reachable; + target = SCNetworkReachabilityCreateWithName(NULL, [hostname cStringUsingEncoding:NSASCIIStringEncoding]); + reachable = SCNetworkReachabilityGetFlags(target, &flags); + CFRelease(target); + + if (!reachable) return FALSE; // If a connection is required, then it's not reachable