zoukankan      html  css  js  c++  java
  • 登录

    NSUserDefaults *use = [NSUserDefaults standardUserDefaults];

            NSLog(@"clientId=%@",[use valueForKey:@"clientId"]);

            AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];

            NSURL *url=[NSURL URLWithString:@"服务器号"];

            NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];

            [request setHTTPMethod:@"POST"];

            NSString *bodyStr = [NSString stringWithFormat:@"phone=%@&password=%@&clientid=%@",_tektextField.text,_passWordTextfield.text,[use valueForKey:@"clientId"]];

            [request setHTTPBody:[bodyStr dataUsingEncoding:NSUTF8StringEncoding]];

            manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

            

            __weak typeof(self) weskSelf=self;

            

            NSOperation *operation = [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {

                

                if ([responseObject[@"code"]isEqualToString:@"100"]) {

    //        //用户id

    //        [[NSUserDefaults standardUserDefaults]setObject:responseObject[@"userid"] forKey:@"用户"];

    //        //马上同步

    //                [[NSUserDefaults standardUserDefaults] synchronize];

    //                NSUserDefaults *user = [NSUserDefaults standardUserDefaults];

    //                NSLog(@"用户%@",[user valueForKey:@"用户"]);

                    

                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"登录成功" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];

                        alert.delegate=self;

                        [alert show];

                        [alert dismissWithClickedButtonIndex:3 animated:YES];

                    [self.navigationController popViewControllerAnimated:YES];

    //                UIStoryboard *main=[UIStoryboard storyboardWithName:@"Main" bundle:nil];

    //                HomepageViewController *hm=[main instantiateViewControllerWithIdentifier:@"HomepageViewController"];

    //                [self.navigationController pushViewController:hm animated:YES];

                    

                    

                    NSLog(@"%@",responseObject);

                    

                    self.nameDic=[NSMutableDictionary dictionaryWithDictionary:responseObject[@"result"]];

                   

                    //登陆成功 将用户id储存到本地 可以在工程的任何地方使用

                    //用户id

                    [[NSUserDefaults standardUserDefaults]setObject:self.nameDic[@"userid"] forKey:@"用户"];

                    //马上同步(必须有这一步)

                    [[NSUserDefaults standardUserDefaults] synchronize];

                    //在需要的时候可以这样取出用户id

                    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];

                    NSLog(@"用户%@",[user valueForKey:@"用户"]);

                    [self.hud show:NO];//菊花停止

                    [self.hud removeFromSuperview];

                }else{

                    [self.hud show:NO];//菊花停止

                    [self.hud removeFromSuperview];

                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"登录失败" message:@"用户名或密码错误" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];

                    [alert show];

                    [alert dismissWithClickedButtonIndex:3 animated:YES];

                    

                }

                

            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

                [self.hud show:NO];//菊花停止

                [self.hud removeFromSuperview];

                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"登陆失败" message:@"请检查网络重试" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

                [alert show];

              //  [alert dismissWithClickedButtonIndex:3 animated:YES];

                

                

                 NSLog(@"Error: %@", error);

            }];

            [manager.operationQueue addOperation:operation];

            

        }

        

  • 相关阅读:
    ASP.NET MVC 4使用jQuery传递对象至后台方法
    大沙发斯蒂芬
    2017年年总结
    Java将HTML导出为PDF
    华硕笔记本安装Ubuntu 17.04版本
    全站启用HTTPS配置详解
    设计模式-1 单例模式
    基础知识扫盲--1 抽象类和接口
    ASP.Net 管道模型 VS Asp.Net Core 管道 总结
    索引深入理解
  • 原文地址:https://www.cnblogs.com/-ios/p/4669660.html
Copyright © 2011-2022 走看看