Latest 0.0.2
Homepage https://github.com/EagleZhangWeicheng/NetRequestLib
License MIT
Platforms ios 8.0, requires ARC
Dependencies AFNetworking
Frameworks UIKit
Authors

封装AFNetworking的网络请求 可以缓请求数据

1、 集成

使用cocoaPos 集成

pod ‘NetRequestLib’,:git => ‘https://github.com/EagleZhangWeicheng/NetRequestLib.git’

pod ‘NetRequestLib’

2、使用

需要工程中全局初始化一次

[NetClient initWithBasicURL:@”https://www.example.com”]; //一定需要初始化一次就行

① 代理使用

NSString *indexURLStr = @”/api/example”;

NetRequest *nr = [[NetRequest alloc] initWithRelativeURLString:indexURLStr delegate:self];

[nr loadData];

-(void)willNetRequest:(NetRequest*) netRequest casheData:(id)data; //请求开始

-(void)netRequestDidFinished:(NetRequest*) netRequest responseData:(id)data; //请求成功走

-(void)netRequestDidFinished:(NetRequest*) netRequest responseData:(id)data; //请求失败

② Block请求使用

[NetClient initWithBasicURL:@”https://www.example.com”];

NSString *indexURL = @”/api/example”;

NetRequest *nr = [[NetRequest alloc] initWithRelativeURLString:indexURL
success:^(id data) {
NSLog(@”block data %@”,data);
} fail:^(NSError *error) {
NSLog(@”block error %@”,error);
}];

[nr loadData];

③ 上传图片

[nr postImageKey:@"imageKey" fileName:@"imageFileName" mimeType:@"image/jpg" image:image];

④ 其他使用

a、缓存数据启用

nr.isUseCashe = true;

-(void)willNetRequest:(NetRequest*) netRequest casheData:(id)data; //这里返回缓存数据

b、加载失败view在viewcontroller中提示 也可以使用自定义的加载

nr.isUseError = true;

4、注意

如果有分页加载数据的情况的话需要处理好分页数据中的缓存

Latest podspec

{
    "name": "NetRequestLib",
    "version": "0.0.2",
    "summary": "u7f51u7edcu8bf7u6c42u5e93",
    "description": "Eagleu7684u7f51u7edcu8bf7u6c42u5e93",
    "homepage": "https://github.com/EagleZhangWeicheng/NetRequestLib",
    "license": "MIT",
    "authors": {
        "Eagle": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/EagleZhangWeicheng/NetRequestLib.git",
        "tag": "0.0.2"
    },
    "source_files": [
        "NetRequestLib/NetRequestLib",
        "NetRequestLib/NetRequestLib/**/*.{h,m}"
    ],
    "frameworks": "UIKit",
    "requires_arc": true,
    "dependencies": {
        "AFNetworking": []
    }
}

Pin It on Pinterest

Share This