Multiple AFNetworking calls In a view controller. The code is very wield.
I think , to negotiate with the server , and combine those into one url, instead of many urls.
@interface HomeViewController ()
#pragma mark - init user info
- (void) initUserData
{
[self get_userInfo];// user login info about
[self getRule];// get ship rule
[self getAppSystem];
[self getPunchCardInfo]; // get work register stauts
[CardTypePickerView updateCardTypes:nil]; // get id type
[self getProblemTypes];
[self getFetch_ad];/ get ad
[self updateSMSCount];// update small messages
[CGAreaData updateAddressList:NO failure:^(NSString *failure) {}];// update province , city , district
}
#pragma mark -- user login info about
- (void)get_userInfo
{
__block UserInfoModel *userInfo = [UserInfoModel getUserInfoModel];
[NetWorkManager info_userSuccess:^(id result, NSString *message) {
userInfo = [UserInfoModel getUserInfoModel];
if ([UiUtil checkIsNull:result] == NO) {
[userInfo setValuesForKeysWithDictionary:result];
[userInfo saveUserInfoModel];
[self.headerTaskView setName:userInfo.realName];
}
} failure:nil];
[self.headerTaskView setName:userInfo.realName];
}
#pragma mark -- get ship rule
- (void)getRule
{
[NetWorkManager getBillRuleWithSuccess:^(NSDictionary *dict) {
if (![UiUtil checkIsNull:dict]) {
[[EGOCache globalCache] setObject:dict forKey:EGO_BAR_RULE];
}
} failure:^(NSString *errmsg) {
}];
}
#pragma mark -- get app version
- (void)getAppSystem
{
[NetWorkManager app_systemWithSuccess:^(NSDictionary *result, NSString *message) {
if (![UiUtil checkIsNull:result]) {
[[EGOCache globalCache] setObject:result forKey:EGO_APP_SYSTEM_RULE];
// check if new version exists
[VersionCheck versionCheckComplete:result[@"VERSION_IOS"]];
}
} failure:^(NSString *errmsg) {
// check if new version exists
}];
}
......
// network request info etc
Under the hood, those functions all use AFNetworking
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
AFHTTPRequestSerializer *requestSerializer = [AFHTTPRequestSerializer serializer];
Any suggestion to optimize these batch requests?
What is the harm of code like this? I think it is the battery consuming.