Latest 2.1.0
Homepage https://github.com/Akateason/XTReq
License MIT
Platforms ios 8.0
Dependencies AFNetworking, XTFMDB, YYModel, SVProgressHUD
Authors

cocoapods

pod 'XTReq'
#import "XTReq.h"

XTRequest

Based on XTFMDB & AFNetworking

  1. share one manager .
  2. async and sync .
  3. GET / POST / PUT , fast append HTTP header / formdata / rawbody
  4. log result
  5. show hud
  6. cancel all req
  7. upload images
  8. download
  9. reachability

XTCacheRequest

  1. Persistent save the response of requests .
  2. three policy for how you save requests .
  3. can control save or not when server crashed or bug .

  • FYI

XTRequest

async

[XTRequest GETWithUrl:kURLstr
            header:nil
            hud:YES
            parameters:nil
            taskSuccess:^(NSURLSessionDataTask *task, id json) {

        } fail:^{

    }] ;

raw body

[XTRequest POSTWithURL:url
                header:
                param:
                rawBody:
                hud:
                success:
                fail: ] ;

sync

id json = [XTRequest syncWithReqMode:
                                 url:
                              header:
                              parameters:] ;

XTCacheRequest

prepare in appDidLaunch

[XTCacheRequest configXTCacheReqWhenAppDidLaunchWithDBName:@"yourDB"] ;

XTCacheRequest judgeResult designated MAIN FUNC

@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

XTReqPolicy

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 ,
} ;

Handling dirty data

use XTReqSaveJudgment block

  • 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 ;
                    }
}] ;

Latest podspec

{
    "name": "XTReq",
    "version": "2.1.0",
    "summary": "u57fau4e8eAFNetworking,u4ee3u7801u6700u5c11,u652fu6301u7f13u5b58u7684u591au79cdu65b9u6848",
    "description": "Based on AFNetworing and sqlite encapsulation, simple APIs and persistent storage requests.",
    "homepage": "https://github.com/Akateason/XTReq",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "teason": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/Akateason/XTReq.git",
        "tag": "2.1.0"
    },
    "source_files": "XTReq/XTReq",
    "public_header_files": "XTReq/XTReq/*.h",
    "dependencies": {
        "AFNetworking": [],
        "XTFMDB": [
            "> 2.0.0"
        ],
        "YYModel": [],
        "SVProgressHUD": []
    }
}

Pin It on Pinterest

Share This