Skip to content

Commit

Permalink
修复部分已知问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ws00801526 committed Aug 6, 2018
1 parent df60f66 commit 67c6f25
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 153 deletions.
4 changes: 2 additions & 2 deletions XMNAFNet.podspec
Expand Up @@ -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' }
Expand All @@ -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
8 changes: 6 additions & 2 deletions XMNAFNet/Classes/Core/XMNAFService.m
Expand Up @@ -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];
}];
}

Expand Down Expand Up @@ -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];
}];
}
}
Expand Down
78 changes: 10 additions & 68 deletions XMNAFNet/Classes/Tools/XMNAFReachabilityManager.h
Expand Up @@ -12,12 +12,12 @@
typedef NS_ENUM(NSUInteger, XMNAFReachablityStatus) {
/** 未知网络状态 */
XMNAFReachablityStatusUnknown = 0,
/** wifi */
XMNAFReachablityStatusWifi,
/** 移动网络 */
XMNAFReachablityStatusWWAN,
/** wifi */
XMNAFReachablityStatusWifi,
/** 2G网络 */
XMNAFReachablityStatus2G,
XMNAFReachablityStatus2G = 100,
/** 3G网络 */
XMNAFReachablityStatus3G,
/** 4G网络 */
Expand All @@ -28,8 +28,9 @@ FOUNDATION_EXPORT NSString *kXMNAFReachabilityStatusChangedNotification;
FOUNDATION_EXPORT NSString *kXMNAFReachabilityStatusKey;
FOUNDATION_EXPORT NSString *kXMNAFReachabilityStatusStringKey;

@protocol XMNAFReachabilityDelegate <NSObject>
typedef void(^XMNAFReachabilityStatusChangedHandler)(XMNAFReachablityStatus status);

@protocol XMNAFReachabilityDelegate <NSObject>
- (void)statusDidChanged:(XMNAFReachablityStatus)status;
@end

Expand All @@ -49,77 +50,18 @@ FOUNDATION_EXPORT NSString *kXMNAFReachabilityStatusStringKey;


@property (nonatomic, weak) id<XMNAFReachabilityDelegate> 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<XMNAFReachabilityDelegate>)delegate;

- (void)startMonitoringWithURL:(NSURL *)URL
statusDidChangedBlock:(void(^)(XMNAFReachablityStatus status))block;
- (void)startMonitoringWithURL:(NSURL *)URL delegate:(id<XMNAFReachabilityDelegate>)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<XMNAFReachabilityDelegate>)delegate;

/**
* @brief 停止监听网络状态
*/
+ (void)stopMonitoring;
+ (instancetype)sharedManager;

/**
* @brief wifi是否可用
Expand Down
107 changes: 26 additions & 81 deletions XMNAFNet/Classes/Tools/XMNAFReachabilityManager.m
Expand Up @@ -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;
Expand All @@ -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<XMNAFReachabilityDelegate>)delegate {
- (void)startMonitoringWithURL:(NSURL *)URL delegate:(id<XMNAFReachabilityDelegate>)delegate {

[self startMonitoringWithURL:URL
delegate:delegate
statusDidChangedBlock:nil];
[self startMonitoringWithURL:URL delegate:delegate handler:nil];
}

- (void)startMonitoringWithURL:(NSURL *)URL
delegate:(id<XMNAFReachabilityDelegate>)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]];
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -185,7 +170,7 @@ - (NSString *)statusString {
case XMNAFReachablityStatusWWAN:
return @"WWAN";
default:
return @"nonetwork";
return @"unknown";
}
}

Expand Down Expand Up @@ -223,69 +208,28 @@ -(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数组 */
-(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<XMNAFReachabilityDelegate>)delegate {

[[XMNAFReachabilityManager sharedManager] startMonitoringWithURL:URL
delegate:delegate
statusDidChangedBlock:nil];
}

+ (void)stopMonitoring {

[[XMNAFReachabilityManager sharedManager] stopMonitoring];
}

/**
* @brief wifi是否可用
*
*/
+(BOOL)isWifiEnable {
+ (BOOL)isWifiEnable {

return [XMNAFReachabilityManager sharedManager].isWifiEnable;
}
Expand All @@ -295,7 +239,7 @@ +(BOOL)isWifiEnable {
*
* @return YES or NO
*/
+(BOOL)isNetworkEnable {
+ (BOOL)isNetworkEnable {

return [XMNAFReachabilityManager sharedManager].isNetworkEnable;
}
Expand All @@ -305,8 +249,9 @@ +(BOOL)isNetworkEnable {
*
* @return YES or NO
*/
+(BOOL)isHighSpeedNetwork {
+ (BOOL)isHighSpeedNetwork {

return [XMNAFReachabilityManager sharedManager].isHighSpeedNetwork;
}

@end

0 comments on commit 67c6f25

Please sign in to comment.