首页 > 代码库 > AFnetworking监测网络变化
AFnetworking监测网络变化
#import <Foundation/Foundation.h>
#import "AFHTTPSessionManager.h"
@interface AFAppDotNetAPIClient :AFHTTPSessionManager
+ (instancetype)sharedClient;
@end
#import "AFAppDotNetAPIClient.h"
staticNSString * const AFAppDotNetAPIBaseURLString =@"https://api.app.net/";
@implementation AFAppDotNetAPIClient
+ (instancetype)sharedClient {
static AFAppDotNetAPIClient *_sharedClient =nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedClient = [[AFAppDotNetAPIClientalloc] initWithBaseURL:[NSURLURLWithString:AFAppDotNetAPIBaseURLString]];
_sharedClient.securityPolicy = [AFSecurityPolicypolicyWithPinningMode:AFSSLPinningModeNone];
[_sharedClient.reachabilityManagersetReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
caseAFNetworkReachabilityStatusReachableViaWWAN:
NSLog(@"-------AFNetworkReachabilityStatusReachableViaWWAN------");
break;
caseAFNetworkReachabilityStatusReachableViaWiFi:
NSLog(@"-------AFNetworkReachabilityStatusReachableViaWiFi------");
break;
caseAFNetworkReachabilityStatusNotReachable:
NSLog(@"-------AFNetworkReachabilityStatusNotReachable------");
break;
default:
break;
}
}];
[_sharedClient.reachabilityManagerstartMonitoring];
});
return _sharedClient;
}
@end
AFnetworking监测网络变化