Marin Todorov
Marin Todorov

Reputation: 6397

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.

Upvotes: 5

Views: 3158

Answers (2)

nonamelive
nonamelive

Reputation: 6510

It will crash if your baseURL is nil.

Upvotes: 6

mattt
mattt

Reputation: 19544

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?

Upvotes: 5

Related Questions