ModifyUserInfoViewController.m
7.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
//
// ModifyUserInfoViewController.m
// CNLiveUserSystemDemo
//
// Created by 朱林 on 16/9/17.
// Copyright © 2016年 zhulin. All rights reserved.
//
#import "ModifyUserInfoViewController.h"
#import "RegistBasicInformationView.h"
@interface ModifyUserInfoViewController ()
@property (nonatomic, strong)UITextField *textField1;
@property (nonatomic, strong)UIButton *saveBtn;
@property (nonatomic, strong)RegistBasicInformationView *registBasicInformationView;
@property (nonatomic, strong)UIButton *verificationBtn;
@end
@implementation ModifyUserInfoViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
backItem.title = @"back";
self.navigationItem.backBarButtonItem = backItem;
if ([self.title isEqualToString:@"更新手机号"]) {
[self.view addSubview:self.registBasicInformationView];
[self.view addSubview:self.verificationBtn];
} else {
[self.view addSubview:self.textField1];
}
[self.view addSubview:self.saveBtn];
}
#pragma mark - action
- (void)saveBtnAction
{
[SVProgressHUD show];
UserInfoModel *model = [UserInfoModel modelWithKeyValues:[Tools getLocalUserInfo]];
if ([self.title isEqualToString:@"更新手机号"]) {
[CNLiveUserSystemCenter updateMobileWithUid:model.uid mobile:_registBasicInformationView.phoneTF.text verificationCode:_registBasicInformationView.verificationTF.text success:^(id result) {
NSLog(@"-----------%@",result);
[SVProgressHUD showSuccessWithStatus:@"手机号修改成功"];
[self.navigationController popViewControllerAnimated:YES];
} failure:^(NSDictionary *errorDic) {
[Tools toast:[NSString stringWithFormat:@"errorCode : %@ \n errorMessage : %@", errorDic[@"errorCode"],errorDic[@"errorMessage"]]];
[SVProgressHUD dismiss];
}];
} else {
[CNLiveUserSystemCenter modifyUserInfoType:_modifyType uid:model.uid modifyInfo:_textField1.text success:^(id result) {
NSLog(@"-----------%@",result);
[SVProgressHUD showSuccessWithStatus:@"修改成功"];
[self.navigationController popViewControllerAnimated:YES];
} failure:^(NSDictionary *errorDic) {
[Tools toast:[NSString stringWithFormat:@"errorCode : %@ \n errorMessage : %@", errorDic[@"errorCode"],errorDic[@"errorMessage"]]];
[SVProgressHUD dismiss];
}];
}
}
- (void)verificationBtnAction
{
[self startTimer];
[CNLiveUserSystemCenter verificationCodeType:VerificationCodeTypeRegister mobile:_registBasicInformationView.phoneTF.text success:^(id result) {
[Tools toast:result[@"errorMessage"]];
} failure:^(NSDictionary *errorDic) {
[Tools toast:[NSString stringWithFormat:@"errorCode : %@ \n errorMessage : %@", errorDic[@"errorCode"],errorDic[@"errorMessage"]]];
}];
}
- (void)startTimer
{
__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(), ^{
//设置界面的按钮显示 根据自己需求设置
[self.verificationBtn setTitle:@"发送验证码" forState:UIControlStateNormal];
self.verificationBtn.userInteractionEnabled = YES;
});
}else{
// int minutes = timeout / 60;
int seconds = timeout % 60;
NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
dispatch_async(dispatch_get_main_queue(), ^{
//设置界面的按钮显示 根据自己需求设置
[self.verificationBtn setTitle:[NSString stringWithFormat:@"%@秒",strTime] forState:UIControlStateNormal];
self.verificationBtn.userInteractionEnabled = NO;
});
timeout--;
}
});
dispatch_resume(_timer);
}
#pragma mark - getter
- (UITextField *)textField1
{
if (!_textField1) {
_textField1 = [[UITextField alloc] initWithFrame:CGRectMake(20, 70, KScreenWidth-40, 50)];
_textField1.autocorrectionType = UITextAutocorrectionTypeNo;
_textField1.autocapitalizationType = UITextAutocapitalizationTypeNone;
_textField1.placeholder = @"请输入更改信息";
_textField1.textColor = [UIColor blackColor];
_textField1.font = [UIFont systemFontOfSize:17];
_textField1.clearButtonMode = UITextFieldViewModeAlways;
}
return _textField1;
}
- (UIButton *)saveBtn
{
if (!_saveBtn) {
_saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_saveBtn setFrame:CGRectMake(10, 250, KScreenWidth - 20, 40)];
[_saveBtn setTitle:@"保 存" forState:UIControlStateNormal];
[_saveBtn addTarget:self action:@selector(saveBtnAction) forControlEvents:UIControlEventTouchUpInside];
_saveBtn.titleLabel.font = [UIFont systemFontOfSize:18];
[_saveBtn setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal];
_saveBtn.layer.cornerRadius = 20;
_saveBtn.layer.masksToBounds = YES;
_saveBtn.layer.borderColor = [UIColor blackColor].CGColor;
_saveBtn.layer.borderWidth = 1;
}
return _saveBtn;
}
- (RegistBasicInformationView *)registBasicInformationView
{
if (!_registBasicInformationView) {
_registBasicInformationView = [[RegistBasicInformationView alloc] initWithFrame:CGRectMake(0, 70, KScreenWidth, 171) hasPwd:NO isPhone:YES];
}
return _registBasicInformationView;
}
- (UIButton *)verificationBtn
{
if (!_verificationBtn) {
_verificationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_verificationBtn setFrame:CGRectMake(KScreenWidth - 105, 80, 95, 37)];
[_verificationBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
[_verificationBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_verificationBtn addTarget:self action:@selector(verificationBtnAction) forControlEvents:UIControlEventTouchUpInside];
_verificationBtn.titleLabel.font = [UIFont systemFontOfSize:15];
[_verificationBtn setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal];
_verificationBtn.layer.cornerRadius = 10;
_verificationBtn.layer.masksToBounds = YES;
_verificationBtn.layer.borderColor = [UIColor blackColor].CGColor;
_verificationBtn.layer.borderWidth = 1;
}
return _verificationBtn;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end