sendAsynchronousRequest 过时
2016-01-02 15:00
363 查看
sendAsynchronousRequest 过时
换成NSURLSession
- (IBAction)onLoginBtnClick:(UIButton *)sender { NSLog(@"start to login."); NSString *loginUrl = [[LSMConstantsUtil hostUrl] stringByAppendingString:[LSMConstantsUtil loginPath]]; NSURL *url = [NSURL URLWithString:loginUrl]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; request.HTTPMethod = @"POST"; UITextField *userNameField = [self.view viewWithTag:10]; NSString *userName = userNameField.text; UITextField *userPasswordField = [self.view viewWithTag:11]; NSString *userPassword = userPasswordField.text; NSDictionary *parameterDict = @{ @"userName" : userName, @"userPassword": userPassword }; NSData *data = [NSJSONSerialization dataWithJSONObject:parameterDict options:NSJSONWritingPrettyPrinted error:nil]; request.HTTPBody = data; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; NSString *sessionIdVar = [[AppDelegate app] sessionId]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { if (data == nil || connectionError) return; NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil]; if (dict[@"sessionId"] != nil && ![dict[@"sessionId"] isEqual: @""]) { [[AppDelegate app] setSessionId:dict[@"sessionId"]]; } NSString *state = dict[@"state"]; if ([@"noUser" isEqualToString:state]) { NSLog(@"Login---noUser"); } else if ([@"failed" isEqualToString:state]) { NSLog(@"Login---failed"); } else if ([@"successful" isEqualToString:state]) { NSLog(@"Login---successful"); } NSString *sessionIdVar = [[AppDelegate app] sessionId]; NSLog([@"sessionId:" stringByAppendingString:sessionIdVar]); }]; }
换成NSURLSession
相关文章推荐
- incredibuild教程
- (java多线程与并发)java并发库中的阻塞队列--BlockingQueue
- Leetcode: Range Sum Query - Mutable && Summary: Segment Tree
- Deep learning From Image to Sequence
- query的参数解析
- codeforces 375D . Tree and Queries 启发式合并 || dfs序+莫队
- Linguistic Data Consortium (LDC)
- 枚举enum用法总结
- easyui datagrid 动态生成列
- Break与Continue的区别
- 设置UICollectionViewCell的尺寸/间距等
- CGRectInset CGRectoffset UIEdgeInsetsInsetRect 这三个函数的使用情况
- Leetcode: Range Sum Query - Mutable
- IO 延迟与Queue Depth
- UICollectionViewCell复用
- Spark UI (基于Yarn) 分析与定制
- UITableViewCell的contentView中的UITextField的值获取的方法
- sunnyxx大神优化UITableViewCell高度计算的那些事
- arduino ide的串口权限解决
- 极客DIY:使用Arduino制作一块开源手表