这里有Casa大神的文章:
iOS应用架构谈 网络层设计方案
虽然挺多高端东西都都不懂,但是大概也弄一个试试水吧,记录一下过程:
viewController中发送请求
业务层,在viewController中直接使用持有的manager调用方法进行请求的发送。
[self.exampleManager requestDataFromAPI];
下面就看manager的这个方法内要做什么:
manager的设计
manager需要继承自一个父类的ZZZBaseAPIManager,并且遵守一项协议ZZZAPIManagerProtocol来提供这个API请求调用所需要的一些信息:
/******************************************************************************/
/* ZZZAPIManagerProtocol */
/* */
/* ZZZBaseAPIManager的派生类必须符合这个protocol */
/******************************************************************************/
@protocol ZZZAPIManagerProtocol <NSObject>
@required
/**
返回服务器的identifier,以此得到特定的server,包含有主机地址、公共头、签名的公共私有key等信息
*/
- (NSString *)serverIdentifier;
/**
返回请求路径中除了主机外的部分
*/
- (NSString *)subURLString;
- (ZZZAPIManagerRequestType)requestType;
// used for pagable API Managers mainly
@optional
/**
确定本接口是否需要缓存,默认为NO(需要缓存时,子类需要实现这一代理方法返回YES)
*/
- (BOOL)shouldCache;
- (NSDictionary *)reformParams:(NSDictionary *)params;
@end