Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

afnetworking - exc_bad_access in startMonitoringNetworkReachability

For a project I have to use AFNetworking. Got fresh copy from github and the iOS example project seems to be working.

However - when I copy over the "AFNetworking" folder to a new Xcode project and try to make a http call, it crashes in the AFHTTPClient's initializer

So in [AFHTTPClient initWithBaseURL:] there's this code:

#ifdef _SYSTEMCONFIGURATION_H
    [self startMonitoringNetworkReachability];
#endif

and it looks really stupid but

1) WHEN I don't link SystemConfiguration - the project doesn't compile

(Undefined symbols for architecture i386: "_SCNetworkReachabilityCreateWithName", referenced from: -[AFHTTPClient startMonitoringNetworkReachability] in AFHTTPClient.o)

2) WHEN I do link SystemConfiguration - the project crashes at runtime inside startMonitoringNetworkReachability with EXC_BAD_ACCESS:

SCNetworkReachabilitySetCallback(self.networkReachability, AFReachabilityCallback, &context);

Did anybody have this problem? From the way they praise their lib on github I thought it'd be more polished.

like image 422
Marin Todorov Avatar asked Feb 19 '12 18:02

Marin Todorov


2 Answers

It will crash if your baseURL is nil.

like image 135
nonamelive Avatar answered Sep 21 '22 23:09

nonamelive


As per the documentation:

This method requires the SystemConfiguration framework. Add it in the active target’s “Link Binary With Library” build phase, and add #import to the header prefix of the project (Prefix.pch).

You included the framework, but did you add #import <SystemConfiguration/SystemConfiguration.h> somewhere in the project?

like image 27
mattt Avatar answered Sep 17 '22 23:09

mattt