iPhone Reachable classes

2019-05-19 22:14发布

问题:

I have added the two files Reachability.h/m. The problem I am having is in the ReachabilityCallback method

NSCAssert([(NSObject*) info isKindOfClass: [Reachability class]], @"info was wrong class in ReachabilityCallback");

The error message is: Cast of C pointer type 'void *' to Objective-C pointer type 'NSObject * requires a bridged cast

NSAutoreleasePool* myPool = [[NSAutoreleasePool alloc] init];

Error: 'NSAutoreleasePool' is unavailable: not available in automatic reference counting mode

SCNetworkReachabilityContext    context = {0, self, NULL, NULL, NULL};

Error: Implicit conversion of an Object-C pointer to 'void *' is disallowed with ARC

There is a bunch of ARC forbids explicit message send of 'release'/'autorelease'.

Is there a version of the code that will work for ARC?

Thanks

回答1:

Try this

NSCAssert([(__bridge NSObject*) info isKindOfClass: [Reachability class]], @"info was wrong class in ReachabilityCallback");


回答2:

Try tonymillion's Reachability classes, they're ARC and GCD compatible.