iOS Reachability


Dave
 

Hi,

A while back I included some code from a sample project that setup Game Center/Kit. This code used a Class called “ Reachability”:

Copyright (c) 2011, Tony Million.
All rights reserved.

From looking at the code it looks quite old and I’m not sure how “right” it is. Is there another version of “Reachability” that I should be using?


When I Compile/Analyse the project, I get warnings on these statements:

+(Reachability*)reachabilityWithHostname:(NSString*)hostname
{
SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithName(NULL, [hostname UTF8String]);
if (ref)
{
id reachability = [[self alloc] initWithReachabilityRef:ref]; //**********************Potential Leak

#if __has_feature(objc_arc)
return reachability;
#else
return [reachability autorelease];
#endif

}


+(Reachability *)reachabilityWithAddress:(const struct sockaddr_in *)hostAddress
{
SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)hostAddress);
if (ref)
{
id reachability = [[self alloc] initWithReachabilityRef:ref]; //**********************Potential Leak

#if __has_feature(objc_arc)
return reachability;
#else
return [reachability autorelease];
#endif
}

return nil;
}


Nimesh Neema <nimeshneema@...>
 

On 24 August 2017 at 15:33, Dave <dave@...> wrote:
Hi,

A while back I included some code from a sample project that setup Game Center/Kit. This code used a Class called “ Reachability”:

 Copyright (c) 2011, Tony Million.
 All rights reserved.

From looking at the code it looks quite old and I’m not sure how “right” it is. Is there another version of “Reachability” that I should be using?


When I Compile/Analyse the project, I get warnings on these statements:

+(Reachability*)reachabilityWithHostname:(NSString*)hostname
{
    SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithName(NULL, [hostname UTF8String]);
    if (ref)
    {
        id reachability = [[self alloc] initWithReachabilityRef:ref];                   //**********************Potential Leak

#if __has_feature(objc_arc)
        return reachability;
#else
        return [reachability autorelease];
#endif

    }


+(Reachability *)reachabilityWithAddress:(const struct sockaddr_in *)hostAddress
{
    SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)hostAddress);
    if (ref)
    {
        id reachability = [[self alloc] initWithReachabilityRef:ref];                   //**********************Potential Leak

#if __has_feature(objc_arc)
        return reachability;
#else
        return [reachability autorelease];
#endif
    }

    return nil;
}













Alex Zavatone
 

There are much newer versions of this. Check on Apple’s sample files and on Github. Stay away from the old copy that you have.

On Aug 24, 2017, at 5:03 AM, Dave <dave@...> wrote:

Hi,

A while back I included some code from a sample project that setup Game Center/Kit. This code used a Class called “ Reachability”:

Copyright (c) 2011, Tony Million.
All rights reserved.

From looking at the code it looks quite old and I’m not sure how “right” it is. Is there another version of “Reachability” that I should be using?


When I Compile/Analyse the project, I get warnings on these statements:

+(Reachability*)reachabilityWithHostname:(NSString*)hostname
{
SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithName(NULL, [hostname UTF8String]);
if (ref)
{
id reachability = [[self alloc] initWithReachabilityRef:ref]; //**********************Potential Leak

#if __has_feature(objc_arc)
return reachability;
#else
return [reachability autorelease];
#endif

}


+(Reachability *)reachabilityWithAddress:(const struct sockaddr_in *)hostAddress
{
SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)hostAddress);
if (ref)
{
id reachability = [[self alloc] initWithReachabilityRef:ref]; //**********************Potential Leak

#if __has_feature(objc_arc)
return reachability;
#else
return [reachability autorelease];
#endif
}

return nil;
}