IOS AFNetworking3.0 SDImage 网络请求和图片加载

首先  下载AF3.0最新版本  地址:https://github.com/AFNetworking/AFNetworking

下载完成后拖入工程;引入头文件

#import "AFHTTPSessionManager.h"

如果是http请添加

  1. 在Info.plist中添加NSAppTransportSecurity类型Dictionary

  2. 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后会出现警告,警告你这个方法已经被舍弃了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值