作者beyondabel,源码BANetworking,一个非常好用的网络框架-BANetworking。
可用于创建网络请求,upload和download网络任务。
使用 ARC 和依赖于 NSURLSession, BANetworking 支持 iOS 7.0 以上和 Mac OS X 10.9
以上。
使用说明:
1. 初始化请求日志
[BANetworking setDebugEnabled:YES];
2. 创建下载任务
BARequest *request = [BARequest GETRequestWithURL:[NSURL URLWithString:@"http://127.0.0.1/avatar"] parameters:nil];
[[[[BAClient currentClient] performRequest:request] onComplete:^(BAResponse *result, NSError *error) {
}] onProgress:^(float progress) {
NSLog(@"download progress = %f",progress);
}];
3. 创建上传任务
BARequest *request = [BARequest POSTRequestWithPath:path parameters:nil];
request.contentType = BARequestContentTypeMultipart;
request.fileData = [BARequestFileData fileDataWithData:data name:fileName fileName:[NSString stringWithFormat:@“%@.png",fileName]];
[[[BAClient currentClient] performRequest:request] onComplete:^(id result, NSError *error) {
if (error) {
NSLog(@"file upload error");
} else {
NSLog(@"file upload succeed");
}
}];
2021-04-05 12:06:02
147KB
IOS源码
1