Latest 2.3.3
Homepage https://github.com/wowbby/HWClient
License MIT
Platforms ios 8.0, requires ARC
Dependencies AFNetworking, YYCache
Frameworks UIKit, Foundation, QuartzCore, CFNetwork
Authors

离散型网络库封装

使用 pod ‘HWClient’

主要classes

1、 HWBaseClient
离散型网络请求client的基类,请求方式支持:


typedef NS_ENUM(NSInteger, HWRequestMethod) {
    HWRequestMethodGet = 0,
    HWRequestMethodPost,
    HWRequestMethodHead,
    HWRequestMethodPut,
    HWRequestMethodDelete,
    HWRequestMethodPatch,
};

Request SerializerType


typedef NS_ENUM(NSInteger, HWRequestSerializerType) {
    HWRequestSerializerTypeHTTP = 0,
    HWRequestSerializerTypeJSON,
};

Response SerializerType


typedef NS_ENUM(NSInteger, HWResponseSerializerType) {
    HWResponseSerializerTypeJSON = 0,
    HWResponseSerializerTypeXML,
    HWResponseSerializerTypeDocment,
    HWResponseSerializerTypePlist,
    HWResponseSerializerTypeImage,
    HWResponseSerializerTypeCompound
};

请求优先级e


typedef NS_ENUM(NSInteger, HWRequestPriority) {
    HWRequestPriorityLow = -4L,
    HWRequestPriorityDefault = 0,
    HWRequestPriorityHigh = 4,
};

回调方式e


block 回调
@property (nonatomic, copy) HWRequestCompletionBlock successCompletionBlock;

@property (nonatomic, copy) HWRequestCompletionBlock failureCompletionBlock;

@property (nonatomic, copy) HWRequestProgressBlock progressBlock;

@property (nonatomic, copy) HWRequestCompletionCacheBlock cacheBlock;

delegate回调

//success and finished callback
- (void)clientRequestFinished:(HWBaseClient *)client;
//failure callback
- (void)clientRequestFailed:(HWBaseClient *)client;
//cancle callback
- (void)clientRequestCancled:(HWBaseClient *)client;
//start callback
- (void)clientRequestStart:(HWBaseClient *)client;
//suspend callback
- (void)clientRequestSuspend:(HWBaseClient *)client;
//uploading callback
- (void)clientRequestUploading:(HWBaseClient *)client progress:(NSProgress *)progress;
//downloading callback
- (void)clientRequestDownLoading:(HWBaseClient *)client progress:(NSProgress *)progress;

2、 HWClientConfig
网络配置,单例:


//为请求添加urlfilter
- (void)addUrlFilter:(id)urlFilter client:(HWBaseClient *)client isCommon:(BOOL)isCommon;
- //通用urlfilter
- (id)commonURLFilter;
- //获取某个client的urlfilter
- (id)urlFilterWithClient:(HWBaseClient *)client;
- //设置缓存key生成机制
- (void)setCacheKeyProtocol:(id)cacheKeyProtocol;
- //获取某个client的缓存key
- (NSString *)cacheKeyOfClient:(HWBaseClient *)client;
3、 HWCacheManager
网络缓存

- (void)cacheObjectWithHWClient:(nonnull HWBaseClient *)client cacheobject:(nonnull id)caCheobject;
- (nullable id)cacheObjectWithHWClient:(nonnull HWBaseClient *)client;
- (void)removeAllCache;
4、 HWNetworkAgent
网络代理,基于afnetworking 3.0 5、 HWUrlSessionTaskManager

- (void)addUrlSessionTask:(NSURLSessionTask *)task;
- (void)cancleTaskWithTaskIndentifire:(NSInteger)indentifire;
- (void)canleAllTask;
- (void)suspendTaskWithTaskIndentifire:(NSInteger)indentifire;
- (void)suspendAllTask;
- (void)resumeTaskWithTaskIndentifire:(NSInteger)indentifire;
- (void)resumeAllTask;
- (void)removeTaskWithTaskIndentifire:(NSInteger)indentifire;
- 

6、 HWClientTool


+ (NSString *)md5StringFromString:(NSString *)string;
+ (NSString *)appVersionString;
+ (NSTimeInterval)timeInterval;
+ (NSTimeInterval)timeInterval:(NSTimeInterval)timeInterval;
- 

-
#示例


LogInClient * request = [[LogInClient alloc]initWithLoginId:@"1213231231231" password:@"123456" accType:11231 thirdpartyAppId:@"" thirdpartyAccessToken:@""];

    [request startWithProgressBlock:^(NSProgress *progress) {

    } successCompletionBlock:^(__kindof HWBaseClient *request) {

    } failureCompletionBlock:^(__kindof HWBaseClient *request) {

    } cacheBlock:^(id cacheObject) {

    }];

 

# 未来
增加并发请求队列与串行请求队列功能;

Latest podspec

{
    "name": "HWClient",
    "version": "2.3.3",
    "summary": "HWClient is a high level request util based on AFNetworking. 3.0",
    "homepage": "https://github.com/wowbby/HWClient",
    "platforms": {
        "ios": "8.0"
    },
    "license": "MIT",
    "authors": {
        "wowbby": "[email protected]"
    },
    "source": {
        "git": "https://github.com/wowbby/HWClient.git",
        "tag": "2.3.3"
    },
    "source_files": "HWClient/*.{h,m}",
    "requires_arc": true,
    "dependencies": {
        "AFNetworking": [
            "~> 3.0"
        ],
        "YYCache": [
            "1.0.3"
        ]
    },
    "libraries": "sqlite3",
    "frameworks": [
        "UIKit",
        "Foundation",
        "QuartzCore",
        "CFNetwork"
    ]
}

Pin It on Pinterest

Share This