Skip to content

Commit

Permalink
新增 AF 模块的头部添加 优化 VM 部分的切换 url 的事情
Browse files Browse the repository at this point in the history
  • Loading branch information
tpctt authored and tpctt committed May 26, 2017
1 parent 0a99af1 commit 98b1bea
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Classes/TimAFAppConnectClient/TimAFAppConnectClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ typedef NS_ENUM(NSUInteger, SKErrorMsgType) {
@property (strong,nonatomic,readonly) NSString* _Nonnull responseDataKey;
//httpDNS
@property (strong,nonatomic) NSDictionary* _Nonnull dnsTable;
///addHTTPHeaderFields
@property (strong,nonatomic) NSDictionary<NSString *, NSString *> * _Nullable addHTTPHeaderFields;



Expand Down
5 changes: 4 additions & 1 deletion Classes/TimAFAppConnectClient/TimAFAppConnectClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,10 @@ - (NSURLSessionDataTask *)POST:(NSString *)URLString
}

}

if (self.addHTTPHeaderFields) {
[request setValuesForKeysWithDictionary:self.addHTTPHeaderFields];

}

if (serializationError) {
if (failure) {
Expand Down
15 changes: 14 additions & 1 deletion Classes/TimBaseListViewModel/TimBaseListViewModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,21 @@ typedef void(^RACCommandFormDdataInput)(id <AFMultipartFormData> _Nullable form

@property (nonatomic, assign ) BOOL allowCacheData;
@property (nonatomic, strong,readonly ) TimAFAppConnectClient *_Nullable appConnectClient;
@property (nonatomic, strong,readonly) NSString * _Nonnull baseUrl;///基本的 url
@property (nonatomic, strong) NSString * _Nonnull baseUrl;///基本的 url

///addHTTPHeaderFields
@property (strong,nonatomic) NSDictionary<NSString *, NSString *> * _Nullable addHTTPHeaderFields;



- (void)initialize ;

+(NSMutableDictionary* _Nonnull)addBaseInfo:(NSDictionary* _Nullable)info forWeb:(BOOL)forWeb;

///cache
-(void)didGetData:(id _Nullable )json subscriber:(id<RACSubscriber>_Nullable) subscriber isCache:(BOOL)isCache;
-(NSString *_Nullable)getCacheKey;

///处理输入参数
-(void)dealInputPara;
//cache
Expand All @@ -61,6 +67,13 @@ typedef void(^RACCommandFormDdataInput)(id <AFMultipartFormData> _Nullable form
//network
-(void)setSucessCode:(NSInteger)sucessCode statusCodeKey:(NSString *_Nonnull)statusCodeKey msgKey:(NSString *_Nonnull)msgKey responseDataKey:(NSString * _Nonnull)responseDataKey;





-(NSString * _Nonnull)baseUrl __attribute__((deprecated("不要使用这个方法设置 baseurl, 请使用 setBaseUrl:")));


@end


Expand Down
31 changes: 25 additions & 6 deletions Classes/TimBaseListViewModel/TimBaseListViewModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,32 @@ -(void)setSucessCode:(NSInteger)sucessCode statusCodeKey:(NSString *_Nonnull)sta

-(void)setBaseUrl:(NSString *)baseUrl
{

NSAssert(baseUrl, @"baseurl 不得为空");

if (_baseUrl == nil) {
if (_baseUrl != baseUrl) {
_baseUrl = baseUrl;
}else{

NSParameterAssert(@"baseurl 设置之后不得修改");
TimAFAppConnectClient *preClient = _appConnectClient;

[self initNetClient];

[_appConnectClient setSucessCode:preClient.sucessCode
statusCodeKey:preClient.statusCodeKey
msgKey:preClient.msgKey
responseDataKey:preClient.responseDataKey];

}else{
// NSParameterAssert(@"baseurl 设置之后不得修改");
}

// NSAssert(baseUrl, @"baseurl 不得为空");
//
// if (_baseUrl == nil) {
// _baseUrl = baseUrl;
// }else{
//
// NSParameterAssert(@"baseurl 设置之后不得修改");
//
// }

}
-(void)dealloc
{
Expand Down Expand Up @@ -214,6 +229,10 @@ - (void)initialize
[self dealInputPara];
[self getCacheData:subscriber];

///add header
self.appConnectClient.addHTTPHeaderFields = self.addHTTPHeaderFields;


///网络请求
[self.appConnectClient skPostWithMethodName:self.path param:self.vmPara constructingBodyWithBlock:^(id<AFMultipartFormData> _Nullable formData) {

Expand Down

0 comments on commit 98b1bea

Please sign in to comment.