Latest 1.4.2
Homepage https://github.com/cnsuer/JLXXNetWorking
License MIT
Platforms ios 9.0
Dependencies AFNetworking
Authors

License MIT
Platform

Example

网络请求类,改编自YTKNetWork

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

JLXXNetWorking is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'JLXXNetWorking'

使用教程参考YTKNetWork

新加项

JLXXRequestConfig && JLXXRequest新加项
  • responseStatusCodeKey
  • successStatusCode
  • responseDescriptionKey

通常服务器返回的json数据中,本次请求的状态码关键字:code,值为200,代表成功,当然了,一个提示语:message,是少不了的,
当请求成功,即code的值为200的话,request的success的回调将被调用,否则faile的回调被调用,此时request.error.descr为message的值:"操作成功"

{
"code": 200,
"data": {
"version": "1.0.1"
},
"message": "操作成功"
}

但是有时候,服务器返回的json数据中,有自己的规则,状态码关键字:res_code,值为P001,代表成功,提示语:res_msg

{
"res_code": "P001",
"data": {
"version": "1.0.1"
},
"res_msg": "操作成功"
}

此时就可以在JLXXRequestConfig,做统一的配置:

[JLXXRequestConfig sharedInstance].responseStatusCodeKey = @"res_code";
[JLXXRequestConfig sharedInstance].responseDescriptionKey = @"res_msg";
[JLXXRequestConfig sharedInstance].successStatusCode = @[@"P001",@"200"];

也可以在每个具体的JLXXRequest子类中,给出相对应的属性

- (NSArray *)successStatusCode{
    return @[@"P001"]
}
JLXXBatchRequest新加项

@property (nonatomic , assign) BOOL isRefresh;

 - (instancetype)initWithAlwaysRequests:(NSArray<JLXXRequest *> *)alwaysRequests refreshRequests:(NSArray<JLXXRequest *> *)refreshRequests;

}

这里常见于一个页面有多个网络请求,下拉刷新的时候全部请求,上拉加载更多的时候,只加载某一个或几个请求,refreshRequests里的request,在上拉加载时,不会请求

{

    JLXXHomeBannerRequest *bannerRequest = [[JLXXHomeBannerRequest alloc] init];
    JLXXHomeTermListTequest *termList = [[JLXXHomeTermListTequest alloc] init];
    JLXXHomeGetLiveRequest *getLive = [[JLXXHomeGetLiveRequest alloc] init];

    JLXXBatchRequest *batchRequest = [[JLXXBatchRequest alloc] initWithAlwaysRequests:@[getLive] refreshRequests:@[bannerRequest,termList] isRefresh: self.isRefresh];

    [batchRequest startWithCompletionBlockWithCallBack:^(JLXXBatchRequest * _Nonnull batchRequest) {

        NSArray *bannerArray = [NSArray array];
        if ([batchRequest requestInSuccessRequestArray:bannerRequest]) {
            bannerArray = [JLXXHomeBannerModel mj_objectArrayWithKeyValuesArray:banner.responseObject[@"data"]];
            [self addData:@[bannerArray] inSection:0];
        }else if(self.isRefresh){//bannerArray没有数据,清空数据,因为是下拉刷新,如果没有数据,需要清空
        [self addData:@[bannerArray] inSection:0];
    }

    NSArray *termListArray = [NSArray array];
    if ([batchRequest requestInSuccessRequestArray:termList]) {
        termListArray = [JLXXHomeTermListModel mj_objectArrayWithKeyValuesArray:termList.responseObject[@"data"]];
        [self addData:@[termListArray] inSection:1];
    }else if(self.isRefresh){//termListArray没有数据,清空数据,因为是下拉刷新,如果没有数据,需要清空
        [self addData:@[termListArray] inSection:1];
    }

    NSArray *roomList = [NSArray array];
    if ([batchRequest requestInSuccessRequestArray:getLive]) {
        roomList = [JLXXHomeLiveModel mj_objectArrayWithKeyValuesArray:getLive.responseObject[@"info"]];
    }else if(self.isRefresh){
        [AlertTool showErrorInView:self.view withTitle:getLive.error.localizedDescription];
    }
    [self addData:roomList inSection:2];

    } allRequestFailure:^(JLXXBatchRequest * _Nonnull batchRequest) {

    }];
}

Author

cnsuer, [email protected]

License

JLXXNetWorking is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "JLXXNetWorking",
    "version": "1.4.2",
    "summary": "JLXXNetWorking.",
    "description": "u7f51u7edcu8bf7u6c42u7c7b,u6539u7f16u81eaYTKNetWork.",
    "homepage": "https://github.com/cnsuer/JLXXNetWorking",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "cnsuer": "[email protected]"
    },
    "source": {
        "git": "https://github.com/cnsuer/JLXXNetWorking.git",
        "tag": "1.4.2"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source_files": "JLXXNetWorking/Classes/**/*",
    "dependencies": {
        "AFNetworking": []
    }
}

Pin It on Pinterest

Share This