问题
Trying to use AFNetworkings ReachabilityStatusChanged but getting
"No visible @interface for HTTPCLIENT declares the selector setReachabilityStatusChangeBlock"
But HttpClient has that function. Anyone know why this is happening?
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://stat-api.herokuapp.com/"]];
[client setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status){
NSLog(@"%d", status);
}];
/// UPDATE ///////////
Here is my .pch file
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "NSDate+Helper.h"
#import "NSEntityDescription+RKAdditions.h"
#import "UIAlertView+MKBlockAdditions.h"
#import "UIActionSheet+MKBlockAdditions.h"
#import "MKBlockAdditions.h"
#import "NSObject+MKBlockAdditions.h"
#import "NSString+Extra.h"
#import "UIView+Additions.h"
#import "ObjectiveSugar.h"
#import "NSNotificationCenter+UniqueNotif.h"
#import "STUIColor+Custom.h"
#import "NSObject+STNSObjectAdditions.h"
#import "UIView+Gradientcy.h"
#import "NSString+USStateMap.h"
#import "STUITextField.h"
#import "UIImage+UIImageCrop.h"
#import "UIBorderLabel.h"
#import <SystemConfiguration/SystemConfiguration.h>
#endif
回答1:
Move
#import <SystemConfiguration/SystemConfiguration.h>
right after this line:
#ifdef __OBJC__
回答2:
Are you sure you're using a version of AFNetworking that have this method?
Also, check this warning from the docs:
Warning: This method requires the
SystemConfiguration
framework.Add it in the active target’s “Link Binary With Library” build phase, and add
#import <SystemConfiguration/SystemConfiguration.h>
to the header prefix of the project (Prefix.pch
).
来源:https://stackoverflow.com/questions/17334237/httpclient-setreachabilitystatuschangedblock-declares-no-interface