基于AFNetworking(3.2.1)和ReactiveObjC的iOS网络请求封装
1.网络状态检测
[[[AFNetworkReachabilityManager sharedManager] rac_startMonitoring] subscribeNext:^(id _Nullable x) {
NSLog(@"%@", x);
}];
[[AFNetworkReachabilityManager sharedManager] stopMonitoring];
2.网络请求
[[self.request start] subscribeStart:^(NSURLSessionTask *task) {
NSLog(@"start");
}
Next:^(EYRequest *_Nullable x) {
NSLog(@"%@", x.responseObject);
}
progress:^(NSProgress *progress) {
NSLog(@"progress:%f", progress.fractionCompleted);
}
error:^(NSError *_Nullable error) {
NSLog(@"error:%@", error);
}
completed:^{
NSLog(@"completed");
}];
- 使用:
pod 'EYNetwork/Client'
网友评论