本项目基于AFNetworking设计,可以配合YYModel``或MJExtension使用,轻量简洁,功能全面,可实现出参``Model化,错误异常捕获,Mock本地JSON。
注意:retry相关方法会在之后的版本中实现
pod 'LXMNetwork'~>1.0.0新建一下LXMInfoHolder工具类遵循LXMNetworkDriverDelegate、LXMNetworkSerialProtocol实现这两个协议的方法,然后新建一个AFHTTPSessionManager的子类,非必要,配置相关参数,具体可以参考Example。
最后AppDelegate启动项目组件,新建基于LXMRequest基类的子类,重写host、path、method、responseClass等方法即可。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[[LXMInfoHolder shareInstance] setupNetworkDriver];
return YES;
}实现responseClass方法
- (Class)responseClass {
return [Model class];
}serialize(NO)- (id)customSerialization:(id)JSON error:(NSError **)error {
return JSON;
}