ifish/Ifish/controllers/IfishTabControllers/我的/mineControllers/pushSetControllrs/ChangeMobleController.m

257 lines
8.8 KiB
Objective-C

//
// ChangeMobleController.m
// Ifish
//
// Created by imac on 15/9/28.
// Copyright © 2015年 imac. All rights reserved.
//
#import "ChangeMobleController.h"
#import "UserModel.h"
#import "AFNetworking.h"
#import "ChangeModelDoneController.h"
#import "XWCountryCodeController.h"
@interface ChangeMobleController ()
@property (weak, nonatomic) IBOutlet UIButton *timerbutton;
@property (weak, nonatomic) IBOutlet UIButton *nextTepBtn;
@property(nonatomic,copy)NSString*verifyData;
@property(nonatomic,copy) NSString *areaCode;
@end
@implementation ChangeMobleController
- (void)viewDidLoad {
[super viewDidLoad];
self.areaCode = @"86";
self.view.backgroundColor= [UIColor colorWithPatternImage:[UIImage imageNamed:@"enter_background"]];
[self addTitleViewWithTitle:@"更换手机号"];
//self.title = @"更换手机号";
UserModel*model=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
NSMutableString*string=[[NSMutableString alloc]initWithString:[CommonUtils getNotNilStr:model.phoneNumber]];
if (string.length>7) {
[string replaceCharactersInRange:NSMakeRange(3, 4) withString:@"***"];
}
self.yuanTelPhone.text=string;
[self.timerbutton addTarget:self action:@selector(startTime) forControlEvents:UIControlEventTouchUpInside];
[self textStyle];
[self.coutryBtn addTarget:self action:@selector(countryCodeAction) forControlEvents:UIControlEventTouchUpInside];
self.view.backgroundColor = [UIColor whiteColor];
}
-(void)textStyle{
self.nextTepBtn.backgroundColor=COLOR_LABEL_TITLE;
self.timerbutton.backgroundColor=COLOR_LABEL_TITLE;
self.sureTextFiled.layer.masksToBounds=YES;
self.sureTextFiled.layer.cornerRadius=5;
self.timerbutton.layer.masksToBounds = YES;
self.timerbutton.layer.cornerRadius = 5;
self.nextTepBtn.layer.masksToBounds = YES;
self.nextTepBtn.layer.cornerRadius = 5;
self.yuanTelPhone.layer.masksToBounds = YES;
self.yuanTelPhone.layer.cornerRadius = 5;
self.countryView.layer.masksToBounds = YES;
self.countryView.layer.cornerRadius = 5;
UIView*phoneView=[[UIView alloc]initWithFrame:CGRectMake(0,0, 10, 10)];
self.yuanTelPhone.leftView=phoneView;
self.yuanTelPhone.leftViewMode=UITextFieldViewModeAlways;
UIView*phoneView1=[[UIView alloc]initWithFrame:CGRectMake(0,0, 10, 10)];
self.sureTextFiled.leftView=phoneView1;
self.sureTextFiled.leftViewMode=UITextFieldViewModeAlways;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
-(void)startTime{
__block int timeout=60; //倒计时时间
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
dispatch_source_set_event_handler(_timer, ^{
if(timeout<=0){ //倒计时结束,关闭
dispatch_source_cancel(_timer);
dispatch_async(dispatch_get_main_queue(), ^{
//设置界面的按钮显示 根据自己需求设置
[_timerbutton setTitle:@"发送验证码" forState:UIControlStateNormal];
_timerbutton.userInteractionEnabled = YES;
});
}else{
// int minutes = timeout / 60;
int seconds = timeout % 60;
NSString *strTime=@"";
if (seconds==0) {
strTime=@"60";
}else{
strTime = [NSString stringWithFormat:@"%.2d", seconds];
}
dispatch_async(dispatch_get_main_queue(), ^{
//设置界面的按钮显示 根据自己需求设置
NSLog(@"____%@",strTime);
[_timerbutton setTitle:[NSString stringWithFormat:@"%@秒",strTime] forState:UIControlStateNormal];
_timerbutton.userInteractionEnabled = NO;
_timerbutton.backgroundColor=[UIColor lightGrayColor];
});
timeout--;
}
});
dispatch_resume(_timer);
[self getAliVeriy];
}
#pragma mark - 获取验证码阿里
-(void)getAliVeriy{
UserModel*model=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
[AFHttpTool getSecurityCodeWithPhoneNumber:model.phoneNumber sendType:@"2" success:^(id response) {
if (response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
// self.sureTextFiled.text=reDic[@"data"];
_verifyData=reDic[@"data"];
// NSLog(@"_verifyData%@",_verifyData);
if ([reDic[@"result"] isEqualToString:@"100"]) {
[self showTitle:@"" messsage:@"发送成功"];
}else if([reDic[@"result"] isEqualToString:@"101"]){
[self showTitle:@"" messsage:@"获取验证失败"];
// 获取验证失败
}else if ([reDic[@"result"] isEqualToString:@"201"]){
[self showTitle:@"" messsage:@"手机已经注册过"];
}else{
}
}
} failure:^(NSError *err) {
UIAlertView *alter =[[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请检查您的网络" delegate:self cancelButtonTitle:@"取消" otherButtonTitles: nil];
[alter show];
}];
}
- (IBAction)netSteep:(id)sender {
UserModel*model=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
if (self.sureTextFiled.text.length==0) {
[self.view makeToast:@"验证码不能为空"];
return;
}
if ([self.sureTextFiled.text isEqualToString:_verifyData])
{
NSLog(@"验证成功");
ChangeModelDoneController *done=[[ChangeModelDoneController alloc]init];
[self.navigationController pushViewController:done animated:YES];
}
else
{
NSString *str =@"验证码验证失败";
[self.view makeToast:str];
}
// [SMSSDK commitVerificationCode:self.sureTextFiled.text phoneNumber:model.phoneNumber zone:self.areaCode result:^(NSError *error) {
//
// {
// if (!error)
// {
//
// NSLog(@"验证成功");
// ChangeModelDoneController *done=[[ChangeModelDoneController alloc]init];
// [self.navigationController pushViewController:done animated:YES];
//
// }
// else
// {
// NSLog(@"错误信息:%@",error);
// NSString *str =@"验证码验证失败";
// [self.view makeToast:str];
// }
// }
// }];
}
#pragma mark-处理收键盘
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self hiddenKeybord];
}
-(void)hiddenKeybord{
[self.sureTextFiled resignFirstResponder];
}
-(void)showTitle:(NSString*)title messsage:(NSString*)message{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
NSTimeInterval dismissSeconds=1.0;
[alert show];
[self performSelector:@selector(dismissAlert:) withObject:alert afterDelay:dismissSeconds];
// UIAlertController *alertContorller=[UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
// UIAlertAction*cancleAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
//
// UIAlertAction *sureAction=[UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:nil];
// [alertContorller addAction:cancleAction];
// [alertContorller addAction:sureAction];
// [self presentViewController:alertContorller animated:YES completion:nil];
}
-(void)dismissAlert:(UIAlertView*)alertView{
[alertView dismissWithClickedButtonIndex:[alertView cancelButtonIndex] animated:YES];
}
-(void)countryCodeAction
{
XWCountryCodeController *CountryCodeVC = [[XWCountryCodeController alloc] init];
//CountryCodeVC.deleagete = self;
[CountryCodeVC toReturnCountryCode:^(NSString *countryCodeStr) {
[self.coutryBtn setTitle:countryCodeStr forState:UIControlStateNormal];
NSArray *array = [countryCodeStr componentsSeparatedByString:@"+"];
self.areaCode = array[1];
}];
[self presentViewController:CountryCodeVC animated:YES completion:nil];
}
@end