阔别一月,好久不见
ASI登录请求
//加载数据
-(void) login{
NSMutableDictionary *postData = [NSMutableDictionary dictionaryWithObjectsAndKeys:
//[userInfo valueForKey:@"cardNo"],@"card_no", // 从用户缓存中取用户card_no
self.username.text,@"loginname",
self.userpwd.text,@"password",
@"xtsessionBP.login",@"service",
nil];
if ([UIApplication sharedApplication].networkActivityIndicatorVisible == NO) {
[Tools showLoadingWindow : self.view textMsg:@"正在登录中..."];
[HttpUtils doPost:[Utils getUrl:@"comurl"] postData:postData delegate:self callback:NSSelectorFromString(@"loadCallback:")];
}
}
AFN登录
//加载数据
-(void) login{
NSMutableDictionary *postData = [NSMutableDictionary dictionaryWithObjectsAndKeys:
//[userInfo valueForKey:@"cardNo"],@"card_no", // 从用户缓存中取用户card_no
self.username.text,@"loginname",
self.userpwd.text,@"password",
@"xtsessionBP.login",@"service",
nil];
[Tools showLoadingWindow : self.view textMsg:@"正在登录中..."];
[[AFNetworkTool sharedManager] HTTPPost:[Constants valueForKey:@"serverUrl"] parameters:postData formdata:^(id<AFMultipartFormData> formdata) {
} progress:^(NSProgress *uploadProgress) {
} success:^(id responseObj) {
[self loadCallback:[NSJSONSerialization JSONObjectWithData:responseObj options:NSJSONReadingAllowFragments error:nil]];
[Tools closeLoadingWindow];
} failure:^(NSError *error) {
[Utils alert:@"错误!" message:[error localizedDescription] delegate:nil];
[Tools closeLoadingWindow];
}];
然后这俩者的区别在于返回数据的那里的data转换,以及参数的形式。
ASI版本更新的代码
__weak ASIFormDataRequest *request = [ASIHttp getASIUpdateRequest];
[request setUploadProgressDelegate:self];
request.showAccurateProgress=YES;
[request setPostValue:@"" forKey:@"service"];
[request setFailedBlock:^{
[Tools closeLoadingWindow];
NSLog(@"请求失败");
[Tools showMsgBox:@"无法连接服务器!"]; }];
[request setCompletionBlock:^{
NSLog(@"服务器版本返回==:%@",[request responseString]);
NSData *responseData = [request responseData];
NSMutableDictionary *retData = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:nil];
//NSString *isSuccess = [retData valueForKey:@"version"];
if (retData!=nil ) {
NSMutableArray *strResult = [retData valueForKey:@"version"];
NSLog(@"===strResult.count=%lu",strResult.count);
NSDictionary *updateInfo = strResult[1][@"ios"];
NSString *server_v = updateInfo[@"versionCode"];
NSString *local_v = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey];
local_v = [local_v stringByReplacingOccurrencesOfString:@"." withString:@""];
NSLog(@"===server_v=%@",server_v);
NSLog(@"===local_v=%@",local_v);
if ([server_v intValue] > [local_v intValue]) {
[Utils alert:@"提示" message:@"App Store已发布《捷佳物业》新版本,请更新!" delegate:nil];
}
[self performSelector:@selector(trunto) withObject:nil afterDelay:2.0f];
}else{
[Utils alert:@"提示" message:@"服务器版本出错!" delegate:nil];
}
}];
//[request startSynchronous];//发送异步请求
[request startAsynchronous];//发送同步请求
}
AFN版本更新的代码
/** 版本更新*/
- (void)versonDefault{
[[AFNetworkTool sharedManager] HTTPGet:@"http://114.55.66.193:8080/bzxzf/mobilenews/version.json" parameters:nil formdata:^(id<AFMultipartFormData> formdata) {
} progress:^(NSProgress *uploadProgress) {
} success:^(id responseObj) {
NSMutableDictionary *retData = [NSJSONSerialization JSONObjectWithData:responseObj options:NSJSONReadingAllowFragments error:nil];
NSLog(@"版本信息:retdata:%@",retData);
if (retData!=nil ) {
NSMutableArray *strResult = [retData valueForKey:@"version"];
NSLog(@"===strResult.count=%lu",strResult.count);
NSDictionary *updateInfo = strResult[1][@"ios"];
NSString *server_v = updateInfo[@"versionCode"];
NSString *local_v = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey];
local_v = [local_v stringByReplacingOccurrencesOfString:@"." withString:@""];
NSLog(@"===server_v=%@",server_v);
NSLog(@"===local_v=%@",local_v);
if ([server_v intValue] > [local_v intValue]) {
[Utils alert:@"提示" message:@"App Store已发布《捷佳物业》新版本,请更新!" delegate:nil];
}
[self performSelector:@selector(trunto) withObject:nil afterDelay:2.0f];
}else{
[Utils alert:@"提示" message:@"服务器版本出错!" delegate:nil];
}
} failure:^(NSError *error) {
[Tools closeLoadingWindow];
NSLog(@"请求失败 -- %@",error);
[Tools showMsgBox:@"无法连接服务器!"];
}];
}
网友评论