首先 下载AF3.0最新版本 地址:https://github.com/AFNetworking/AFNetworking
下载完成后拖入工程;引入头文件
#import "AFHTTPSessionManager.h"
如果是http请添加
-
在Info.plist中添加
NSAppTransportSecurity
类型Dictionary
。 -
在
NSAppTransportSecurity
下添加NSAllowsArbitraryLoads
类型Boolean
,值设为YES
开始请求
AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
NSDictionary *dic = @{@"UserID":@"1",@"Page":@"1",@"PageSize":@"1",@"Type":@"4"};
[session POST:@"写入地址" parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSString *string = [NSString stringWithFormat:@"%@",responseObject[@"retmsg"]];
NSData *jsonData = [string dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
allArray = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
[self.oneTabelView reloadData];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];
[self.view addSubview:self.oneTabelView];
需要下载SDimage这个工具,在git上先下载好
导入:
#import "UIImageView+WebCache.h"
然后直接调用:
[cell.imageViewsd_setImageWithURL:allArray[0][@"imgUrl"]placeholderImage:[UIImageimageNamed:@"yindao04"]];
就OK了
在这里说明一点,AF也有个图片加载的SDimage,但是这个方法好像已经不行了,用的话直接就会崩溃,并且你导入了SDimage后会出现警告,警告你这个方法已经被舍弃了