PoporAFN 4.06

PoporAFN 4.06

popor维护。



  • 作者:
  • popor

MyBox

PoporAFN

CI Status Version License Platform

示例

要运行示例项目,首先克隆仓库,从Example目录运行pod install

封装了AFN方法,支持网络监测功能(通过PoporNetRecord控制)。

[PoporAFNTool getUrl:@"https://api.androidhive.info/volley/person_object.json" parameters:@{@"test":@"test1"} success:nil failure:nil monitor:YES];

要求

安装

PoporAFN 可以通过 CocoaPods 获得。要安装它,只需将以下行添加到您的 Podfile 中

pod 'PoporAFN'
// 可以 设置head
PoporAFNConfig * config = [PoporAFNConfig share];
config.afnSMBlock = ^AFHTTPSessionManager *{
	AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

	manager.requestSerializer  = [AFJSONRequestSerializer serializer];
	manager.responseSerializer = [AFHTTPResponseSerializer serializer];
	manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil]; // 不然不支持www.baidu.com.

	[manager.requestSerializer setValue:@"iOS" forHTTPHeaderField:@"system"];
	[manager.requestSerializer setValue:@"popor" forHTTPHeaderField:@"name"];

	manager.completionQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

	manager.requestSerializer.timeoutInterval = 10.0f;

	return manager;
};

// 用法示例
[PoporAFNTool url:@"https://www.baidu.com" method:PoporMethodGet parameters:nil success:^(NSString * _Nonnull url, NSData * _Nonnull data, NSDictionary * _Nonnull dic) {

} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

}];

0.0.14: 不再默认持有网络监测功能,假如需要网络监测需要 pod 'PoporNetRecord'
并且设置监测回调block.

PoporAFNConfig * config = [PoporAFNConfig share];
config.recordBlock = ^(NSString *url, NSString *title, NSString *method, id head, id parameters, id response) {
    [PoporNetRecord addUrl:url title:title method:method head:head parameter:parameters response:response];
};

1.02: 应对AFN 4.0 最低iOS9.0

1.03: 注释了过时的代码,修复了之前的仓促修改,允许单独设置 header 或使用默认的 manager.header。更新了接口。

1.04: 增加了 form-data 请求类型和 progress 接口。鉴于种类繁多,修改了 PoporAfnRecordBlock 的 method 定义

1.06: 将 manager 和 header 分开设置,更新了请求方式,增加了 post data 的功能。

1.07: 为 manager 增加了注释示例。

作者

wangkq,[email protected]

许可

PoporAFN 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。