cocoapods
pod 'XTReq'
#import "XTReq.h"
Based on XTFMDB & AFNetworking & ReactiveCocoa
- share one manager .
- async and sync .
- GET / POST / PUT , fast append HTTP header / formdata / rawbody
- log result
- show hud
- cancel all req
- upload images
- download
- reachability
- RAC signal
- Persistent save the response of requests .
- three policy for how you save requests .
- can control save or not when server crashed or bug .
- FYI
[XTRequest GETWithUrl:kURLstr
header:nil
hud:YES
parameters:nil
taskSuccess:^(NSURLSessionDataTask *task, id json) {
} fail:^{
}] ;
[XTRequest POSTWithURL:url
header:
param:
rawBody:
hud:
success:
fail: ] ;
id json = [XTRequest syncWithReqMode:
url:
header:
parameters:] ;
prepare in appDidLaunch
[XTCacheRequest configXTCacheReqWhenAppDidLaunchWithDBName:@"yourDB"] ;
@param reqMode XTRequestMode get / post mode .
@param url string
@param hud bool
@param header dic HTTP header if has .
@param param dic param if has .
@param body str post rawbody if has .
@param cachePolicy XTReqPolicy req policy .
@param overTimeIfNeed INT (seconds) only in XTReqPolicyOverTime mode .
@param completion (XTReqSaveJudgment(^)(BOOL isNewest, id json))completion
PARAM isNewest : isCacheOrNewest
PARAM json : respObj
RETURN XTReqSaveJudgment : judge If Need Cache
typedef NS_OPTIONS(NSUInteger, XTReqPolicy) {
XTReqPolicy_NeverCache_WaitReturn = XTResponseCachePolicyNeverUseCache | XTResponseReturnPolicyWaitUtilReqDone , // DEFAULT
XTReqPolicy_AlwaysCache_WaitReturn = XTResponseCachePolicyAlwaysCache | XTResponseReturnPolicyWaitUtilReqDone ,
XTReqPolicy_OverTime_WaitReturn = XTResponseCachePolicyOverTime | XTResponseReturnPolicyWaitUtilReqDone ,
XTReqPolicy_NeverCache_IRTU = XTResponseCachePolicyNeverUseCache | XTResponseReturnPolicyImmediatelyReturnThenUpdate ,
XTReqPolicy_AlwaysCache_IRTU = XTResponseCachePolicyAlwaysCache | XTResponseReturnPolicyImmediatelyReturnThenUpdate ,
XTReqPolicy_OverTime_IRTU = XTResponseCachePolicyOverTime | XTResponseReturnPolicyImmediatelyReturnThenUpdate ,
} ;
- XTReqSaveJudgment_willSave
- XTReqSaveJudgment_NotSave
[XTCacheRequest cacheGET:kURLstr
parameters:nil
judgeResult:^XTReqSaveJudgment(id json) {
if (!json) {
return XTReqSaveJudgment_NotSave ; // dirty data will not save
}
else {
[self showInfoInAlert:[json yy_modelToJSONString]] ;
return XTReqSaveJudgment_willSave ;
}
}] ;