IOSLaiHH

NSAppTransportSecurity:Dictionary
NSAllowsArbitraryLoads:Boolean YES

#import "ViewController.h"

@interface ViewController ()<NSURLSessionDelegate>

@property (strong, nonatomic) UITextField *userFile;
@property (strong, nonatomic) UITextField *passFile;

@property (copy, nonatomic) NSString *userStr;
@property (copy, nonatomic) NSString *passStr;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    UITextField *userFile = [[UITextField alloc] initWithFrame:CGRectMake(50, 100, self.view.frame.size.width-100, 44)];
    self.userFile = userFile;
    self.userFile.delegate = self;
    userFile.placeholder = @"请输入用户";
    userFile.backgroundColor =[UIColor lightGrayColor];
    [self.view addSubview:userFile];
    
    
    UITextField *passFile = [[UITextField alloc] initWithFrame:CGRectMake(50, 150, self.view.frame.size.width-100, 44)];
    self.passFile = passFile;
    self.passFile.delegate = self;
    passFile.placeholder = @"请输入密码";
    passFile.backgroundColor =[UIColor lightGrayColor];
    [self.view addSubview:passFile];
    
    
    UIButton *loginBtn = [[UIButton alloc] initWithFrame:CGRectMake(50, 200, 100, 44)];
    [loginBtn setTitle:@"登录" forState:UIControlStateNormal];
    [loginBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [loginBtn addTarget:self action:@selector(loginMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginBtn];
    
}

-(void)textFieldDidEndEditing:(UITextField *)textField{
    
    if(textField == self.userFile){
        self.userStr = textField.text;
        NSLog(@"%@",self.userStr);
    }else{
        self.passStr = textField.text;
        NSLog(@"%@",self.passStr);
    }

}



- (void)loginMethod {
    NSURLSession *session = [NSURLSession sharedSession];
    NSURL *url = [NSURL URLWithString:@"http://172.20.10.2:8080/login.json"];
    // 通过URL初始化task,在block内部可以直接对返回的数据进行处理
    NSURLSessionTask *task = [session dataTaskWithURL:url
                                    completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                        
//                                        weakSelf.dict =  [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
                                        
                               
                                        NSLog(@"%@", [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil]);
                                    }];
    // 启动任务
    [task resume];
    
    
}

@end
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • # 一度蜜v3.0协议 --- # 交互协议 [TOC] ## 协议说明 ### 请求参数 下表列出了v3.0版协...
    c5e350bc5b40阅读 3,938评论 0 0
  • iOS 10 适配 ATS 一. HTTPS其实HTTPS从最终的数据解析的角度,与HTTP没有任何的区别,HTT...
    lanceChris阅读 4,738评论 0 0
  • Info.plist 用于向 iOS 提供关于 app , bundle 或者 framework 的一些重要信息...
    Alfred_小乐阅读 7,317评论 1 0
  • iOS 10 适配 ATS 一. HTTPS 其实HTTPS从最终的数据解析的角度,与HTTP没有任何的区别,HT...
    made_China阅读 5,667评论 0 12
  • 三月如澧, 春风醉了一抹斜阳; 八月有你, 氤氲了所有的中秋节气。 如果可以, 请在梦中相见, 看看你敛裾望月的模...
    臣不依阅读 1,598评论 0 3

友情链接更多精彩内容