标签:ios 网络连接状态 网络连接类型 判断网络连接 网络
在.h中
#import <Foundation/Foundation.h>
#import "AFHTTPSessionManager.h"
@interface NetworkingManager : AFHTTPSessionManager
+ (instancetype)shareClient;
@end
在.m中
#import "NetworkingManager.h"
static NSString *const AFAppDotNetAPIBaseURLString = @"www.baidu.com";
@implementation NetworkingManager
+(instancetype)shareClient
{
static NetworkingManager *_shareClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken,^{
_shareClient = [[NetworkingManager alloc] initWithBaseURL:[NSURL URLWithString:AFAppDotNetAPIBaseURLString]];
_shareClient.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
[_shareClient.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusReachableViaWWAN:
NSLog(@"network is viawwan");//2G/3G
break;
case AFNetworkReachabilityStatusReachableViaWiFi:
NSLog(@"network is wifi");//wifi
break;
case AFNetworkReachabilityStatusNotReachable:
NSLog(@"network isnot able");//无连接
break;
default:
break;
}
}];
[_shareClient.reachabilityManager startMonitoring];
});
return _shareClient;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:ios 网络连接状态 网络连接类型 判断网络连接 网络
原文地址:http://blog.csdn.net/lu_ca/article/details/46787543