diff --git a/XMNAFNet.podspec b/XMNAFNet.podspec index 5975020..4ec0fff 100644 --- a/XMNAFNet.podspec +++ b/XMNAFNet.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'XMNAFNet' - s.version = '0.4.4' + s.version = '0.4.5' s.summary = '基于AFNetworking封装的网络请求类库' s.homepage = 'https://github.com/ws00801526/XMNAFNet' s.license = { :type => 'MIT', :file => 'LICENSE' } @@ -33,6 +33,6 @@ Pod::Spec.new do |s| ss.dependency 'XMNAFNet/Core' ss.dependency 'YYCache' ss.dependency 'YYModel' - ss.compiler_flags = '-Wno-format', '-Wno-everything' + ss.compiler_flags = '-Wno-format', '-Wno-everything', '-Wno-documentation' end end diff --git a/XMNAFNet/Classes/Core/XMNAFService.m b/XMNAFNet/Classes/Core/XMNAFService.m index ab9b489..c65b728 100644 --- a/XMNAFNet/Classes/Core/XMNAFService.m +++ b/XMNAFNet/Classes/Core/XMNAFService.m @@ -85,8 +85,10 @@ - (instancetype)initWithConfiguration:(NSURLSessionConfiguration *)configuration _sessionManager.responseSerializer = [AFJSONResponseSerializer serializer]; if (self.commonHeaders.count) { + __weak typeof(self) wSelf = self; [self.commonHeaders enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { - [_sessionManager.requestSerializer setValue:obj forHTTPHeaderField:key]; + __strong typeof(wSelf) self = wSelf; + [self->_sessionManager.requestSerializer setValue:obj forHTTPHeaderField:key]; }]; } @@ -121,8 +123,10 @@ - (void)setRequestSerializerType:(XMNAFRequestSerializerType)type { _sessionManager.requestSerializer.HTTPShouldHandleCookies = YES; if (self.commonHeaders.count) { + __weak typeof(self) wSelf = self; [self.commonHeaders enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { - [_sessionManager.requestSerializer setValue:obj forHTTPHeaderField:key]; + __strong typeof(wSelf) self = wSelf; + [self->_sessionManager.requestSerializer setValue:obj forHTTPHeaderField:key]; }]; } } diff --git a/XMNAFNet/Classes/Tools/XMNAFReachabilityManager.h b/XMNAFNet/Classes/Tools/XMNAFReachabilityManager.h index 351c506..170c5a3 100644 --- a/XMNAFNet/Classes/Tools/XMNAFReachabilityManager.h +++ b/XMNAFNet/Classes/Tools/XMNAFReachabilityManager.h @@ -12,12 +12,12 @@ typedef NS_ENUM(NSUInteger, XMNAFReachablityStatus) { /** 未知网络状态 */ XMNAFReachablityStatusUnknown = 0, - /** wifi */ - XMNAFReachablityStatusWifi, /** 移动网络 */ XMNAFReachablityStatusWWAN, + /** wifi */ + XMNAFReachablityStatusWifi, /** 2G网络 */ - XMNAFReachablityStatus2G, + XMNAFReachablityStatus2G = 100, /** 3G网络 */ XMNAFReachablityStatus3G, /** 4G网络 */ @@ -28,8 +28,9 @@ FOUNDATION_EXPORT NSString *kXMNAFReachabilityStatusChangedNotification; FOUNDATION_EXPORT NSString *kXMNAFReachabilityStatusKey; FOUNDATION_EXPORT NSString *kXMNAFReachabilityStatusStringKey; -@protocol XMNAFReachabilityDelegate +typedef void(^XMNAFReachabilityStatusChangedHandler)(XMNAFReachablityStatus status); +@protocol XMNAFReachabilityDelegate - (void)statusDidChanged:(XMNAFReachablityStatus)status; @end @@ -49,77 +50,18 @@ FOUNDATION_EXPORT NSString *kXMNAFReachabilityStatusStringKey; @property (nonatomic, weak) id delegate; -@property (nonatomic, copy) void(^statusDidChangedBlock)(XMNAFReachablityStatus status); - - -+ (instancetype)sharedManager; +@property (nonatomic, copy) XMNAFReachabilityStatusChangedHandler statusDidChangedBlock; - (void)startMonitoring; - (void)startMonitoringWithURL:(NSURL *)URL; - -- (void)startMonitorWithURL:(NSURL *)URL - delegate:(id)delegate; - -- (void)startMonitoringWithURL:(NSURL *)URL - statusDidChangedBlock:(void(^)(XMNAFReachablityStatus status))block; +- (void)startMonitoringWithURL:(NSURL *)URL delegate:(id)delegate; +- (void)startMonitoringWithURL:(NSURL *)URL handler:(XMNAFReachabilityStatusChangedHandler)handler; - (void)stopMonitoring; +#pragma mark - Class -#pragma mark - Class Methods - -/// ======================================== -/// @name 以下方法均为直接操作[XMNAFReachabilityManager sharedManager] -/// ======================================== - -/** - * @brief 获取当前的网络状态 - * - * @return 当前网络状态 - */ -+ (XMNAFReachablityStatus)currentStatus; - -/** - * @brief 获取当前网络状态对应字符串 - * - * @return 当前状态字符创 - */ -+ (NSString *)currentStatusString; - -/** - * @brief 开始检测网络状态 - */ -+ (void)startMonitoring; - -/** - * @brief 开始检测网络状态 - * - * @param URL 测试连接的网络地址 - */ -+ (void)startMonitoringWithURL:(NSURL *)URL; - -/** - * @brief 开始检测网络状态 - * - * @param URL 测试连接的网络地址 - * @param block block回调 - */ -+ (void)startMonitoringWithURL:(NSURL *)URL - statusDidChangedBlock:(void(^)(XMNAFReachablityStatus status))block; - -/** - * @brief 开始检测网络状态 - * - * @param URL 测试连接的网络地址 - * @param delegate delegate方式回调 - */ -+ (void)startMonitoringWithURL:(NSURL *)URL - delegate:(id)delegate; - -/** - * @brief 停止监听网络状态 - */ -+ (void)stopMonitoring; ++ (instancetype)sharedManager; /** * @brief wifi是否可用 diff --git a/XMNAFNet/Classes/Tools/XMNAFReachabilityManager.m b/XMNAFNet/Classes/Tools/XMNAFReachabilityManager.m index 19a20df..0415f6b 100644 --- a/XMNAFNet/Classes/Tools/XMNAFReachabilityManager.m +++ b/XMNAFNet/Classes/Tools/XMNAFReachabilityManager.m @@ -38,12 +38,12 @@ @interface XMNAFReachabilityManager () @implementation XMNAFReachabilityManager +#pragma mark - Life + + (instancetype)sharedManager { - static id manager; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - manager = [[[self class] alloc] init]; }); return manager; @@ -57,47 +57,33 @@ - (void)dealloc { [self stopMonitoring]; } - (void)startMonitoring { - [self startMonitoringWithURL:nil - delegate:nil - statusDidChangedBlock:nil]; + [self startMonitoringWithURL:nil delegate:nil handler:nil]; } - (void)startMonitoringWithURL:(NSURL *)URL { - [self startMonitoringWithURL:URL - delegate:nil - statusDidChangedBlock:nil]; + [self startMonitoringWithURL:URL delegate:nil handler:nil]; } -- (void)startMonitoringWithURL:(NSURL *)URL - statusDidChangedBlock:(void (^)(XMNAFReachablityStatus status))block { +- (void)startMonitoringWithURL:(NSURL *)URL handler:(XMNAFReachabilityStatusChangedHandler)handler { - [self startMonitoringWithURL:URL - delegate:nil - statusDidChangedBlock:block]; + [self startMonitoringWithURL:URL delegate:nil handler:handler]; } -- (void)startMonitorWithURL:(NSURL *)URL - delegate:(id)delegate { +- (void)startMonitoringWithURL:(NSURL *)URL delegate:(id)delegate { - [self startMonitoringWithURL:URL - delegate:delegate - statusDidChangedBlock:nil]; + [self startMonitoringWithURL:URL delegate:delegate handler:nil]; } - (void)startMonitoringWithURL:(NSURL *)URL delegate:(id)delegate - statusDidChangedBlock:(void (^)(XMNAFReachablityStatus status))block { + handler:(XMNAFReachabilityStatusChangedHandler)handler { - if (self.isMonitoring) { - - XMNLog(@"reachability is monitoring"); - [self stopMonitoring]; - } + if (self.isMonitoring) { [self stopMonitoring]; } self.delegate = delegate; - self.statusDidChangedBlock = block; + self.statusDidChangedBlock = handler; if (URL) { self.reachability = [Reachability reachabilityWithHostName:[URL host]]; @@ -139,7 +125,6 @@ - (void)handleStatusChanged:(NSNotification *)notification { kXMNAFReachabilityStatusStringKey:self.statusString}; [[NSNotificationCenter defaultCenter] postNotificationName:kXMNAFReachabilityStatusChangedNotification object:self userInfo:userInfo]; - /** block回调 */ self.statusDidChangedBlock ? self.statusDidChangedBlock(self.status) : nil; @@ -185,7 +170,7 @@ - (NSString *)statusString { case XMNAFReachablityStatusWWAN: return @"WWAN"; default: - return @"nonetwork"; + return @"unknown"; } } @@ -223,14 +208,16 @@ -(NSArray *)technology2GArray{ return @[CTRadioAccessTechnologyEdge,CTRadioAcces /** @brief 3G数组 */ -(NSArray *)technology3GArray{ - return @[CTRadioAccessTechnologyHSDPA, - CTRadioAccessTechnologyWCDMA, - CTRadioAccessTechnologyHSUPA, - CTRadioAccessTechnologyCDMA1x, - CTRadioAccessTechnologyCDMAEVDORev0, - CTRadioAccessTechnologyCDMAEVDORevA, - CTRadioAccessTechnologyCDMAEVDORevB, - CTRadioAccessTechnologyeHRPD]; + return @[ + CTRadioAccessTechnologyHSDPA, + CTRadioAccessTechnologyWCDMA, + CTRadioAccessTechnologyHSUPA, + CTRadioAccessTechnologyCDMA1x, + CTRadioAccessTechnologyCDMAEVDORev0, + CTRadioAccessTechnologyCDMAEVDORevA, + CTRadioAccessTechnologyCDMAEVDORevB, + CTRadioAccessTechnologyeHRPD + ]; } /** @brief 4G数组 */ @@ -238,54 +225,11 @@ -(NSArray *)technology4GArray{ return @[CTRadioAccessTechnologyLTE]; } #pragma mark - Class Methods -+ (XMNAFReachablityStatus)currentStatus { - - return [XMNAFReachabilityManager sharedManager].status; -} - -+ (NSString *)currentStatusString { - - return [XMNAFReachabilityManager sharedManager].statusString; -} - -+ (void)startMonitoring { - - [[XMNAFReachabilityManager sharedManager] startMonitoring]; -} - -+ (void)startMonitoringWithURL:(NSURL *)URL { - - [[XMNAFReachabilityManager sharedManager] startMonitoringWithURL:URL - delegate:nil - statusDidChangedBlock:nil]; -} - -+ (void)startMonitoringWithURL:(NSURL *)URL - statusDidChangedBlock:(void(^)(XMNAFReachablityStatus status))block { - - [[XMNAFReachabilityManager sharedManager] startMonitoringWithURL:URL - delegate:nil - statusDidChangedBlock:block]; -} - -+ (void)startMonitoringWithURL:(NSURL *)URL - delegate:(id)delegate { - - [[XMNAFReachabilityManager sharedManager] startMonitoringWithURL:URL - delegate:delegate - statusDidChangedBlock:nil]; -} - -+ (void)stopMonitoring { - - [[XMNAFReachabilityManager sharedManager] stopMonitoring]; -} - /** * @brief wifi是否可用 * */ -+(BOOL)isWifiEnable { ++ (BOOL)isWifiEnable { return [XMNAFReachabilityManager sharedManager].isWifiEnable; } @@ -295,7 +239,7 @@ +(BOOL)isWifiEnable { * * @return YES or NO */ -+(BOOL)isNetworkEnable { ++ (BOOL)isNetworkEnable { return [XMNAFReachabilityManager sharedManager].isNetworkEnable; } @@ -305,8 +249,9 @@ +(BOOL)isNetworkEnable { * * @return YES or NO */ -+(BOOL)isHighSpeedNetwork { ++ (BOOL)isHighSpeedNetwork { return [XMNAFReachabilityManager sharedManager].isHighSpeedNetwork; } + @end