简单说明下YYRequest的使用吧 我看到很多AFN的封装基本都是一个类方法的套用,这样写的话的确很方便适用于简单的业务 我也参考了YTKNetWorking 但是YTK的封装比较重 我结合两点写了轻量级YYRequest也是为了减少C层代码 使用如下
YYBaseRequest *request = [YYBaseRequest new];
request.requestMethod = YYRequestMethodGET; //默认GET
request.url = @"v1/userInfo";
request.requestParameters = @{};//字典参数
[request startRequestSuccessCallBack:^(__kindof YYBaseRequest *request) {
NSLog(@"%@",request.responseObject);
} failureCallBack:^(__kindof YYBaseRequest
*request) {
NSLog(@"%@",request.error);
}];
loginRequest *logRequest = [[loginRequest alloc] initWithLoginRequest:@"" passWord:@""];
[logRequest startRequestSuccessCallBack:^(__kindof YYBaseRequest *request) {
NSLog(@"%@",request.responseObject);
} failureCallBack:^(__kindof YYBaseRequest *request) {
NSLog(@"%@",request.error);
}];
UIImage *imag = [UIImage imageNamed:@""];
YYBaseRequest *requstPath = [YYBaseRequest new];
request.requestMethod = YYRequestMethodPATCH; //图片上传
request.image = @[imag];
request.imageSize = 0.8f;
[requstPath startRequestSuccessCallBack:^(__kindof YYBaseRequest *request) {
NSLog(@"%@",request.uploadProgress); //上传进度
NSLog(@"%@",request.responseObject); //成功回调
} failureCallBack:^(__kindof YYBaseRequest *request) {
NSLog(@"%@",request.error);
}];
YYBaseRequest *downRequst = [YYBaseRequest new];
downRequst.requestMethod = YYRequestDownTask;
NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
//设置下载路径
downRequst.resumableDownloadPath = filePath;
[downRequst startRequestSuccessCallBack:^(__kindof YYBaseRequest *request) {
NSLog(@"返回的下载Url = %@",request.responseObject);
} failureCallBack:^(__kindof YYBaseRequest *request) {
}];
####详细参考demo
- 下载YYRequest文件夹内的所有内容
- 将YYRequest内的源文件添加(拖放)到你的工程。
- 导入YYRequest