LoginViewController.m 19.3 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10 11
//
//  LoginViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/4/27.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "LoginViewController.h"
#import "CustomTabbarController.h"
#import "AppDelegate.h"
曹云霄's avatar
曹云霄 committed
12
#import "authenticateView.h"
勾芒's avatar
勾芒 committed
13 14 15 16
#import "SceneLibraryViewController.h"
#import "ProductLibraryViewController.h"
#import "AllCustomerViewController.h"
#import "CustomerOrderViewController.h"
曹云霄's avatar
曹云霄 committed
17 18
#import <Bugly/Bugly.h>

19 20

@interface LoginViewController ()<RightVCselectedDelegate>
曹云霄's avatar
曹云霄 committed
21 22

@property (nonatomic,strong) MMDrawerController *drawerController;
23 24
@property (nonatomic,strong) CustomTabbarController *customtabbar;

曹云霄's avatar
曹云霄 committed
25 26 27 28 29 30 31 32 33
/**
 *  验证身份View
 */
@property (nonatomic,strong) authenticateView *identityView;

/**
 *  重置密码View
 */
@property (nonatomic,strong) authenticateView *resetPasswordView;
34

曹云霄's avatar
曹云霄 committed
35 36 37 38 39
/**
 *  定时器
 */
@property (nonatomic,strong) NSTimer *sendTimer;

勾芒's avatar
勾芒 committed
40 41 42 43 44 45 46 47 48
/**
 *  用户名
 */
@property (nonatomic,copy) NSString *userNameString;
/**
 *  密码
 */
@property (nonatomic,copy) NSString *passWordString;

49 50 51 52 53 54 55 56 57 58
/**
 * companyName
 */
@property (weak, nonatomic) IBOutlet UIImageView *companyName;

/**
 *  背景大图
 */
@property (weak, nonatomic) IBOutlet UIImageView *backImageView;

59 60 61 62 63 64
/**
 *  版本号
 */
@property (weak, nonatomic) IBOutlet UILabel *versionlabel;


65

曹云霄's avatar
曹云霄 committed
66 67 68 69
@end

@implementation LoginViewController

70 71 72 73 74 75 76 77 78 79

- (CustomTabbarController *)customtabbar
{
    if (_customtabbar == nil) {
        
        _customtabbar = [[CustomTabbarController alloc]init];
    }
    return _customtabbar;
}

曹云霄's avatar
曹云霄 committed
80 81 82
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
83 84

    [self uiConfigAction];
曹云霄's avatar
曹云霄 committed
85 86 87 88
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        [self exitApplication];
//    });

曹云霄's avatar
曹云霄 committed
89 90
}

曹云霄's avatar
曹云霄 committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
//#pragma mark - 强制退出app
//- (void)exitApplication {
//    
//    [UIView beginAnimations:@"exitApplication" context:nil];
//    [UIView setAnimationDuration:0.5];
//    [UIView setAnimationDelegate:self];
//    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:SHARED_APPDELEGATE.window cache:NO];
//    [UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
//    SHARED_APPDELEGATE.window.bounds = CGRectMake(0, 0, 0, 0);
//    [UIView commitAnimations];
//}
//
//- (void)animationFinished:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
//    if ([animationID compare:@"exitApplication"] == 0) {
//        exit(0);
//    }
//}

曹云霄's avatar
曹云霄 committed
109

勾芒's avatar
勾芒 committed
110

111 112 113 114 115 116 117 118 119 120 121 122
#pragma mark - 布局
- (void)uiConfigAction
{
    self.loginButton.layer.masksToBounds = YES;
    self.loginButton.layer.cornerRadius = kCornerRadius;
    self.userNameBackview.layer.masksToBounds = YES;
    self.userNameBackview.layer.cornerRadius = kCornerRadius;
    self.passWordBackview.layer.masksToBounds = YES;
    self.passWordBackview.layer.cornerRadius = kCornerRadius;
    self.userNameLoginView.layer.masksToBounds = YES;
    self.userNameLoginView.layer.cornerRadius = 10;
    self.forgotPasswordButton.titleLabel.font = [UIFont boldSystemFontOfSize:16];
曹云霄's avatar
曹云霄 committed
123
    
勾芒's avatar
勾芒 committed
124 125 126 127 128
    //加载本地的用户名密码
    self.userNameString = [[NSUserDefaults standardUserDefaults] objectForKey:USERNAME];
    self.passWordString = [[NSUserDefaults standardUserDefaults] objectForKey:PASSWORD];
    self.userName.text = self.userNameString;
    self.passWord.text = self.passWordString;
曹云霄's avatar
曹云霄 committed
129 130
    //版本更新
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectionUpdateVersion) name:UPLOADVERSION object:nil];
131
    self.versionlabel.text = [self getAppVersion];
132
    [self detectionUpdateVersion];
133 134 135 136 137
}


#pragma mark -登陆
- (IBAction)LoginButtonClick:(UIButton *)sender {
曹云霄's avatar
曹云霄 committed
138

勾芒's avatar
勾芒 committed
139

140 141 142 143 144 145 146 147 148
    if (self.userName.text.length == 0) {
        [self ErrorMBProgressView:@"用户名不能为空"];
        return;
    }else if (self.passWord.text.length == 0)
    {
        [self ErrorMBProgressView:@"密码不能为空"];
        return;
    }
    [self judgeUserNameAndPassword];
149
    
曹云霄's avatar
曹云霄 committed
150 151
}

152 153 154
#pragma mark -设置根视图控制器
- (void)SetTheRootViewController
{
155
    RightViewController *rightVC = [[self getStoryboardWithName] instantiateViewControllerWithIdentifier:@"RightViewController"];
勾芒's avatar
勾芒 committed
156 157 158 159 160 161 162
    rightVC.delegate = self;
    UINavigationController *rightNav = [[UINavigationController alloc]initWithRootViewController:rightVC];
    self.drawerController = [[MMDrawerController alloc]initWithCenterViewController:self.customtabbar rightDrawerViewController:rightNav];
    [self.drawerController setMaximumRightDrawerWidth:RightWidth];
    [self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
    [self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
    SHARED_APPDELEGATE.mmdrawer = self.drawerController;
勾芒's avatar
勾芒 committed
163
    [self restoreRootViewController:self.drawerController];
勾芒's avatar
勾芒 committed
164
    SHARED_APPDELEGATE.Mytabbar = self.customtabbar;
165 166 167
}


勾芒's avatar
勾芒 committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189

#pragma mark -切换rootViewcontroller
- (void)restoreRootViewController:(UIViewController *)rootViewController
{
    typedef void (^Animation)(void);
    UIWindow* window = SHARED_APPDELEGATE.window;
    rootViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    Animation animation = ^{
        BOOL oldState = [UIView areAnimationsEnabled];
        [UIView setAnimationsEnabled:NO];
        window.rootViewController = rootViewController;
        [UIView setAnimationsEnabled:oldState];
    };
    
    [UIView transitionWithView:window
                      duration:0.5f
                       options:UIViewAnimationOptionTransitionFlipFromTop
                    animations:animation
                    completion:nil];
}


190 191 192 193 194 195 196
#pragma mark -判断用户名密码是否正确
- (void)judgeUserNameAndPassword
{
    [self CreateMBProgressHUDLoding];
    LoginInfo *login = [[LoginInfo alloc]init];
    login.username = self.userName.text;
    login.password = self.passWord.text;
曹云霄's avatar
曹云霄 committed
197
    WS(weakSelf);
198
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(LOGIN) WithCallClass:weakSelf WithRequestType:0 WithParameter:login WithReturnValueBlock:^(id returnValue) {
199
        
曹云霄's avatar
曹云霄 committed
200
        [weakSelf RemoveMBProgressHUDLoding];
201 202
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
曹云霄's avatar
曹云霄 committed
203 204
            //设置检测用户标示
            [Bugly setUserIdentifier:self.userName.text];
205
            
曹云霄's avatar
曹云霄 committed
206 207 208
            //保持导购信息
            LoginResult *result = [[LoginResult alloc]initWithDictionary:returnValue[@"data"] error:nil];
            [Shoppersmanager manager].Shoppers = result;
曹云霄's avatar
曹云霄 committed
209 210
            [Shoppersmanager manager].userNameString = weakSelf.userName.text;
            [Shoppersmanager manager].passWordString = weakSelf.passWord.text;
勾芒's avatar
勾芒 committed
211
            //保存用户名密码
曹云霄's avatar
曹云霄 committed
212 213
            [[NSUserDefaults standardUserDefaults] setObject:weakSelf.userName.text forKey:USERNAME];
            [[NSUserDefaults standardUserDefaults] setObject:weakSelf.passWord.text forKey:PASSWORD];
勾芒's avatar
勾芒 committed
214
            [[NSUserDefaults standardUserDefaults] synchronize];
215
            
曹云霄's avatar
曹云霄 committed
216
            [weakSelf SetTheRootViewController];
217 218
        }else
        {
曹云霄's avatar
曹云霄 committed
219
            [weakSelf ErrorMBProgressView:returnValue[@"message"]];
220 221 222
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
曹云霄's avatar
曹云霄 committed
223
        [weakSelf RemoveMBProgressHUDLoding];
曹云霄's avatar
曹云霄 committed
224
        [weakSelf ErrorMBProgressView:NETWORK];
225
    } WithFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
226
        [weakSelf RemoveMBProgressHUDLoding];
曹云霄's avatar
曹云霄 committed
227
        [weakSelf ErrorMBProgressView:error.localizedDescription];
228 229 230 231
    }];
}


232
#pragma mark -RightVCselectedDelegate 方法
曹云霄's avatar
曹云霄 committed
233
- (void)SelectedControllerWithIndex:(NSString *)Name
234
{
勾芒's avatar
勾芒 committed
235
    SHARED_APPDELEGATE.lineView.hidden = YES;
236
    NSInteger selectedIndex = 0;
曹云霄's avatar
曹云霄 committed
237
    if ([Name isEqualToString:@"体验中心"]) {
勾芒's avatar
勾芒 committed
238
 
曹云霄's avatar
曹云霄 committed
239
        [[NSNotificationCenter defaultCenter] postNotificationName:OPENFOLLOWHEARTVC object:nil];
240
        return;
曹云霄's avatar
曹云霄 committed
241 242 243
        
    }else if ([Name isEqualToString:@"场景库"])
    {
244 245
        selectedIndex = 4;
        SceneLibraryViewController *sceneVC = [SHARED_APPDELEGATE.allControllerArray objectAtIndex_opple:4];
246 247
        sceneVC.conditionModel.styleEquals = nil;
        sceneVC.conditionModel.spaceEquals = nil;
勾芒's avatar
勾芒 committed
248
        [sceneVC.StyleButton setTitle:@"风格" forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
249
        [sceneVC.SpaceButton setTitle:@"空间" forState:UIControlStateNormal];
勾芒's avatar
勾芒 committed
250 251
        [sceneVC.seceneLibararyCollectionView.mj_header beginRefreshing];
       
曹云霄's avatar
曹云霄 committed
252 253
    }else if ([Name isEqualToString:@"产品库"])
    {
254 255
        selectedIndex = 5;
        ProductLibraryViewController *productVC = [SHARED_APPDELEGATE.allControllerArray objectAtIndex_opple:5];
256
        //默认加载全部数据
勾芒's avatar
勾芒 committed
257
        productVC.barcode = nil;
258 259 260 261 262 263 264 265
        productVC.selectedCode = nil;
        productVC.condtionModel.categoryEquals = nil;
        productVC.condtionModel.styleEquals = nil;
        productVC.condtionModel.spaceEquals = nil;
        productVC.condtionModel.materialEqueals = nil;
        productVC.condtionModel.startprice = nil;
        productVC.condtionModel.endprice = nil;
        productVC.condtionModel.nameLike = nil;
勾芒's avatar
勾芒 committed
266
        [productVC.productCollectionView.mj_header beginRefreshing];
曹云霄's avatar
曹云霄 committed
267 268
    }else if ([Name isEqualToString:@"所有客户"])
    {
269 270
        selectedIndex = 6;
        AllCustomerViewController *AllcustomerVC = [SHARED_APPDELEGATE.allControllerArray objectAtIndex_opple:6];
271 272 273 274 275 276
        AllcustomerVC.searchTextfield.text = nil;
        AllcustomerVC.conditionModel.resellerCodeEquals = nil;
        AllcustomerVC.conditionModel.mobileEquals = nil;
        AllcustomerVC.conditionModel.createTimeBegin = nil;
        AllcustomerVC.conditionModel.createTimeEnd = nil;
        AllcustomerVC.conditionModel.page = nil;
勾芒's avatar
勾芒 committed
277
        [AllcustomerVC.allCustomerTableview.mj_header beginRefreshing];
曹云霄's avatar
曹云霄 committed
278 279
    }else if ([Name isEqualToString:@"客户订单"])
    {
280 281
        selectedIndex = 7;
        CustomerOrderViewController *customerVC = [SHARED_APPDELEGATE.allControllerArray objectAtIndex_opple:7];
282
        customerVC.searchCustomerOrder.text = nil;
曹云霄's avatar
曹云霄 committed
283
        [customerVC.StyleButton setTitle:@"全部订单" forState:UIControlStateNormal];
284 285
        customerVC.model.consumerNameOrMobileEquals = nil;
        customerVC.model.orderStateEquals = nil;
勾芒's avatar
勾芒 committed
286
        [customerVC.customerOrderTableView.mj_header beginRefreshing];
曹云霄's avatar
曹云霄 committed
287 288
    }else if ([Name isEqualToString:@"关于"])
    {
289
        selectedIndex = 8;
290
    }
zhu's avatar
zhu committed
291
   self.customtabbar.selectedIndex = selectedIndex;
292 293 294 295
}



曹云霄's avatar
曹云霄 committed
296 297 298
#pragma mark -忘记密码
- (IBAction)ForgotpasswordButtonClick:(UIButton *)sender {
    self.identityView = [[[NSBundle mainBundle] loadNibNamed:@"authenticateView" owner:self options:nil]firstObject];
299
    //判断登陆界面是否已经输入了用户名,如果有则直接引用,否则报错
300 301
    if (self.userName.text.length != 0) {
        self.identityView.userName.text = self.userName.text;
302 303 304 305 306
    } else {
        
        [self ErrorMBProgressView:@"请填写您的用户名"];
        self.passWord.text = @"";
        return;
307 308 309
    }
    self.identityView.layer.masksToBounds = YES;
    self.identityView.layer.cornerRadius = 10;
曹云霄's avatar
曹云霄 committed
310 311
    [self.identityView.backLoginButton addTarget:self action:@selector(BackloginButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.identityView.nextButton addTarget:self action:@selector(NextButtonClick) forControlEvents:UIControlEventTouchUpInside];
曹云霄's avatar
曹云霄 committed
312
    [self.identityView.SendButton addTarget:self action:@selector(SendButtonClick) forControlEvents:UIControlEventTouchUpInside];
曹云霄's avatar
曹云霄 committed
313 314 315 316 317 318 319 320
    self.identityView.alpha = 0;
    self.identityView.frame = self.userNameLoginView.frame;
    [self.view addSubview:self.identityView];
    [UIView animateWithDuration:0.2 animations:^{
        self.identityView.alpha = 1;
    }];
}

曹云霄's avatar
曹云霄 committed
321 322 323
#pragma mark -发送验证码
- (void)SendButtonClick
{
曹云霄's avatar
曹云霄 committed
324
    WS(weakSelf);
曹云霄's avatar
曹云霄 committed
325 326 327 328 329 330 331 332 333
    NSString *inputPhoneNumber = self.identityView.bindingPhoneNumber.text;
    if (inputPhoneNumber.length == 0) {
        [self ErrorMBProgressView:@"手机号不能为空"];
        return;
    }
    if (![HENLENSONG isValidateMobile:inputPhoneNumber]) {
        [self ErrorMBProgressView:@"手机号码格式不正确"];
        return;
    }
334
    [self CreateMBProgressHUDLoding];
曹云霄's avatar
曹云霄 committed
335
    //发送验证码
曹云霄's avatar
曹云霄 committed
336
    NSString *urlString = [NSString stringWithFormat:SERVERREQUESTURL(SENDSMS),inputPhoneNumber,self.identityView.userName.text];
337
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:urlString WithCallClass:weakSelf WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
338
        [weakSelf RemoveMBProgressHUDLoding];
339
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
曹云霄's avatar
曹云霄 committed
340 341 342 343
            [weakSelf ErrorMBProgressView:@"发送验证码成功"];
            [weakSelf.identityView.SendButton setTitle:@"60" forState:UIControlStateNormal];
            weakSelf.identityView.SendButton.enabled = NO;
            weakSelf.sendTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(SendbuttonChangetitle) userInfo:nil repeats:YES];
344 345
        }else
        {
曹云霄's avatar
曹云霄 committed
346
            [weakSelf ErrorMBProgressView:returnValue[@"message"]];
347
        }
曹云霄's avatar
曹云霄 committed
348
    } WithErrorCodeBlock:^(id errorCodeValue) {
曹云霄's avatar
曹云霄 committed
349 350
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf ErrorMBProgressView:NETWORK];
351
    } WithFailureBlock:^(NSError *error) {
曹云霄's avatar
曹云霄 committed
352 353
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf ErrorMBProgressView:error.localizedDescription];
曹云霄's avatar
曹云霄 committed
354 355
    }];
}
曹云霄's avatar
曹云霄 committed
356

曹云霄's avatar
曹云霄 committed
357 358 359 360 361 362 363 364 365 366 367
#pragma mark -倒计时
- (void)SendbuttonChangetitle
{
    NSInteger number = [self.identityView.SendButton.currentTitle integerValue];
    if (number <= 0) {
        [self.identityView.SendButton setTitle:@"发送" forState:UIControlStateNormal];
        self.identityView.SendButton.enabled = YES;
        [self.sendTimer invalidate];
        return;
    }
    number --;
曹云霄's avatar
曹云霄 committed
368
    [self.identityView.SendButton setTitle:[NSString stringWithFormat:@"%ld",number] forState:UIControlStateNormal];
曹云霄's avatar
曹云霄 committed
369 370
    
}
曹云霄's avatar
曹云霄 committed
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386


#pragma mark -返回登陆界面
- (void)BackloginButtonClick
{
    [UIView animateWithDuration:0.2 animations:^{
        self.identityView.alpha = 0;
    }completion:^(BOOL finished) {
        [self.identityView removeFromSuperview];
    }];
}


#pragma mark -下一步(重置密码界面)
- (void)NextButtonClick
{
387 388 389 390
    // 验证码必须填写
    if (self.identityView.verificationCode.text.length == 0) {
        [self ErrorMBProgressView:@"验证码不能为空"];
        return;
391
        
392
    } else {
393 394 395 396 397 398 399 400 401 402 403 404
        
        [self.sendTimer invalidate];
        self.resetPasswordView = [[[NSBundle mainBundle] loadNibNamed:@"authenticateView" owner:self options:nil]lastObject];
        self.resetPasswordView.layer.masksToBounds = YES;
        self.resetPasswordView.layer.cornerRadius = 10;
        self.resetPasswordView.frame = self.userNameLoginView.frame;
        [self.resetPasswordView.backValidationView addTarget:self action:@selector(backButonClick) forControlEvents:UIControlEventTouchUpInside];
        [self.resetPasswordView.resetPasswordNextButton addTarget:self action:@selector(ChangPassWordRequest) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:self.resetPasswordView];
        self.resetPasswordView.alpha = 0;
        [UIView animateWithDuration:0.2 animations:^{
            self.resetPasswordView.alpha = 1;
405
        }];
406
    }
407 408 409 410 411 412 413
}


#pragma mark -修改密码
- (void)ChangPassWordRequest
{
    if (self.resetPasswordView.newpass.text.length == 0) {
曹云霄's avatar
曹云霄 committed
414
        
415 416 417 418 419 420 421 422 423 424 425 426
        [self ErrorMBProgressView:@"新密码为空"];
        return;
    }else if (self.resetPasswordView.confirmNewpass.text.length == 0)
    {
        [self ErrorMBProgressView:@"确认密码为空"];
        return;
    }
    if (![self.resetPasswordView.newpass.text isEqualToString:self.resetPasswordView.confirmNewpass.text]) {
        
        [self ErrorMBProgressView:@"两次密码不相同"];
        return;
    }
曹云霄's avatar
曹云霄 committed
427
    [self CreateMBProgressHUDLoding];
428 429
    //重置密码接口
    ResetPasswordRequest *passwrod = [[ResetPasswordRequest alloc]init];
430 431
    passwrod.fnewPassword = self.resetPasswordView.newpass.text;
    passwrod.username = self.userName.text;
432
    passwrod.smsCode = self.identityView.verificationCode.text;
曹云霄's avatar
曹云霄 committed
433
    WS(weakSelf);
434
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(RESETPASSWORD) WithCallClass:weakSelf WithRequestType:0 WithParameter:passwrod WithReturnValueBlock:^(id returnValue) {
435
        
曹云霄's avatar
曹云霄 committed
436
        [weakSelf RemoveMBProgressHUDLoding];
437 438
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
曹云霄's avatar
曹云霄 committed
439 440 441
            [weakSelf ErrorMBProgressView:@"重置密码成功"];
            weakSelf.passWord.text = weakSelf.resetPasswordView.newpass.text;
            [weakSelf judgeUserNameAndPassword];
442 443
        }else
        {
曹云霄's avatar
曹云霄 committed
444
           [weakSelf ErrorMBProgressView:returnValue[@"message"]];
445 446 447 448
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
449
    } WithFailureBlock:^(NSError *error) {
450
        
曹云霄's avatar
曹云霄 committed
451 452
        [weakSelf ErrorMBProgressView:error.localizedDescription];
        [weakSelf RemoveMBProgressHUDLoding];
453
    }];
曹云霄's avatar
曹云霄 committed
454 455 456
}


457

曹云霄's avatar
曹云霄 committed
458 459 460 461 462 463 464 465
#pragma mark -返回验证信息界面
- (void)backButonClick
{
    [UIView animateWithDuration:0.2 animations:^{
        self.resetPasswordView.alpha = 0;
    } completion:^(BOOL finished) {
        [self.resetPasswordView removeFromSuperview];
    }];
466 467 468 469 470 471
    // 重置发送按钮
    [self.identityView.SendButton setTitle:@"发送" forState:UIControlStateNormal];
    self.identityView.SendButton.enabled = YES;
    [self.sendTimer invalidate];
    // 清空验证码
    self.identityView.verificationCode.text = @"";
曹云霄's avatar
曹云霄 committed
472 473
}

474 475 476 477 478 479 480 481 482
#pragma mark - 检测更新
- (void)detectionUpdateVersion
{
    NSString *path = [[NSBundle mainBundle]pathForResource:@"Info" ofType:@"plist"];
    NSDictionary* content =[NSDictionary dictionaryWithContentsOfFile:path];
    NSString *version = [content valueForKey:@"CFBundleShortVersionString"];
    //获取服务端版本大小
    WS(weakSelf);
    NSString *string = [NSString stringWithFormat:@"/employee/getUpgrade?apptype=IOS&version=%@",version];
483
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:SERVERREQUESTURL(string) WithCallClass:weakSelf WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
484 485 486
        
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            NSDictionary *dict = returnValue[@"data"];
曹云霄's avatar
曹云霄 committed
487
            UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"发现新版本%@,快去更新吧!",dict[@"version"]] preferredStyle:UIAlertControllerStyleAlert];
488 489
            [alertVC addAction:[UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:dict[@"url"]]];
曹云霄's avatar
曹云霄 committed
490
//                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-services://?action=download-manifest&url=http://www.pgyer.com/app/plist/95fcb4e47cf3d6c7309a2760ccccde66"]];
491 492
            }]];
            //是否强制更新
曹云霄's avatar
曹云霄 committed
493
            if (![dict[@"forceupdate"] isEqualToString:@"1"]) {
494 495 496 497 498 499 500 501 502 503 504 505
                [alertVC addAction:[UIAlertAction actionWithTitle:@"以后再说" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                    [weakSelf dismissViewControllerAnimated:YES completion:nil];
                }]];
            }
            [weakSelf presentViewController:alertVC animated:YES completion:nil];
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        [weakSelf ErrorMBProgressView:@"网络不可用,请检查网络连接"];
    } WithFailureBlock:^(NSError *error) {
        [weakSelf ErrorMBProgressView:error.localizedDescription];
    }];
曹云霄's avatar
曹云霄 committed
506 507 508
}

@end