ViewController.m
10 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
//
// ViewController.m
// CNLiveUserSystemDemo
//
// Created by iOS on 16/9/12.
// Copyright © 2016年 zhulin. All rights reserved.
//
#import "ViewController.h"
#import "LoginViewController.h"
#import "RegisterViewController.h"
#import "UserInfoViewController.h"
#import "CNLiveLogout.h"
#import "UserInfoSava.h"
#import "ThirdPartyView.h"
#import "CNLiveThirdLoginManager.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource,ThirdPartyViewDelegate,UIGestureRecognizerDelegate>
{
NSArray *_dataArr;
}
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) ThirdPartyView *thirPartydView;
@property (nonatomic, strong) UIButton *loginBtn;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"用户云 SDK Demo";
self.view.backgroundColor = [UIColor whiteColor];
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
backItem.title = @"back";
self.navigationItem.backBarButtonItem = backItem;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetHeight([UIScreen mainScreen].bounds)-40, CGRectGetWidth(self.view.frame), 30)];
label.text = @"北京中投视讯文化传媒股份有限公司";
[self.view addSubview:label];
label.font = [UIFont systemFontOfSize:12];
label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:label];
[self.view addSubview:self.tableView];
[self.view addSubview:self.loginBtn];
[self.view addSubview:self.thirPartydView];
_dataArr = @[@"通过手机号修改密码",@"更新附加信息",@"修改用户信息",@"查询用户信息",@"反馈",@"绑定第三方账号"];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if ([Tools isLogin]) {
[_loginBtn setTitle:@"注销" forState:UIControlStateNormal];
} else {
[_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
}
[_tableView reloadData];
}
#pragma mark - action
- (void)logoutBtnAction
{
if ([Tools isLogin]) {
[CNLiveLogout clearLocalUserInfo];
[Tools setUserLogin:NO];
[_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
[_tableView reloadData];
} else {
LoginViewController *loginVC = [[LoginViewController alloc] init];
[self.navigationController pushViewController:loginVC animated:YES];
}
}
- (void)tapGesturedDetected:(UITapGestureRecognizer *)recognizer
{
[UIView animateWithDuration:0.25 animations:^{
_thirPartydView.frame = CGRectMake(0, KScreenHeight, KScreenWidth, 160);
}];
}
#pragma mark - ThirdPartyViewDelegate
- (void)thirdPartyBtnAction:(NSString *)title
{
if ([title isEqualToString:@"微信"]) {
[[CNLiveThirdLoginManager manager] weChatLoginIsBindingThirdParty:YES];
} else if ([title isEqualToString:@"微博"]) {
[[CNLiveThirdLoginManager manager] sinaLoginIsBindingThirdParty:YES];
} else {
[[CNLiveThirdLoginManager manager] qqLoginIsBindingThirdParty:YES];
}
[UIView animateWithDuration:0.25 animations:^{
_thirPartydView.frame = CGRectMake(0, KScreenHeight, KScreenWidth, 160);
}];
}
- (void)cancelThirdView
{
[UIView animateWithDuration:0.25 animations:^{
_thirPartydView.frame = CGRectMake(0, KScreenHeight, KScreenWidth, 160);
}];
}
#pragma mark - UITableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([Tools isLogin]) {
return _dataArr.count+1;
} else {
return 1;
}
return _dataArr.count+1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
UITableViewCell *loginCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellID"];
UIImageView *iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 80, 80)];
iconImg.layer.cornerRadius = 40;
iconImg.layer.masksToBounds = YES;
[loginCell.contentView addSubview:iconImg];
UserInfoModel *model = [UserInfoModel modelWithKeyValues:[Tools getLocalUserInfo]];
[iconImg sd_setImageWithURL:[NSURL URLWithString:model.faceUrl] placeholderImage:[UIImage imageNamed:@"touxiang"]];
UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(120, 0, KScreenWidth- 160, 120)];
if ([Tools isLogin]) {
name.text = @"已登录";
} else {
name.text = @"登录";
}
[loginCell.contentView addSubview:name];
return loginCell;
} else {
static NSString *cellIndentify = @"cellIndentify";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentify];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentify];
}
cell.textLabel.text = [NSString stringWithFormat:@"%@",_dataArr[indexPath.row-1]];
return cell;
}
return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.row == 1) {
RegisterViewController *regVC = [[RegisterViewController alloc] init];
regVC.type = @"forgetPwd";
[self.navigationController pushViewController:regVC animated:YES];
}
if (indexPath.row == 2) {
[SVProgressHUD show];
UserInfoModel *model = [UserInfoModel modelWithKeyValues:[Tools getLocalUserInfo]];
[CNLiveUserSystemCenter updateOtherInfoWithUid:model.uid extInfo:@"将要更新的附加信息,NSString类型" 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];
}];
}
if (indexPath.row == 3) {
UserInfoViewController *userInfo = [[UserInfoViewController alloc] init];
[self.navigationController pushViewController:userInfo animated:YES];
}
if (indexPath.row == 4) {
UserInfoModel *model = [UserInfoModel modelWithKeyValues:[Tools getLocalUserInfo]];
[CNLiveUserSystemCenter queryUserInfoWithUid:model.uid srcUid:model.uid success:^(id result) {
NSLog(@"%@",result);
NSDictionary *dic = result[@"data"];
NSString *message = [NSString stringWithFormat:@" uid:%@\n nickName:%@\n gender:%@\n location:%@\n extInfo:%@\n mobile:%@\n email:%@",dic[@"uid"],dic[@"nickName"],dic[@"gender"],dic[@"location"],dic[@"extInfo"],dic[@"mobile"],dic[@"email"]];
NSString *icon = dic[@"faceUrl"];
[UserInfoSava setLocalUserInfo:icon withKey:@"faceUrl"];
[_tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
[Tools toast:message];
} failure:^(NSDictionary *errorDic) {
[Tools toast:[NSString stringWithFormat:@"errorCode : %@ \n errorMessage : %@", errorDic[@"errorCode"],errorDic[@"errorMessage"]]];
}];
}
if (indexPath.row == 5) {
[CNLiveUserSystemCenter feedbackWithContentId:@"11" message:@"fhsjhifkncznshfu" success:^(id result) {
[Tools toast:[NSString stringWithFormat:@"反馈--%@",result[@"errorMessage"]]];
} failure:^(NSDictionary *errorDic) {
[Tools toast:[NSString stringWithFormat:@"errorCode : %@ \n errorMessage : %@", errorDic[@"errorCode"],errorDic[@"errorMessage"]]];
}];
}
if (indexPath.row == 6) {
[UIView animateWithDuration:0.25 animations:^{
_thirPartydView.frame = CGRectMake(0, KScreenHeight-160, KScreenWidth, 160);
}];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
return 120;
} else {
return 50;
}
}
#pragma mark - getter
- (UITableView *)tableView
{
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, KScreenWidth, KScreenHeight - 120 - 64) style:UITableViewStylePlain];
_tableView.backgroundColor = [UIColor whiteColor];
_tableView.tableFooterView = [[UIView alloc] init];
_tableView.delegate = self;
_tableView.dataSource = self;
}
return _tableView;
}
- (ThirdPartyView *)thirPartydView
{
if (!_thirPartydView) {
_thirPartydView = [[ThirdPartyView alloc] initWithFrame:CGRectMake(0, KScreenHeight, KScreenWidth, 160) binding:YES];
_thirPartydView.delegate = self;
}
return _thirPartydView;
}
- (UIButton *)loginBtn
{
if (!_loginBtn) {
_loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_loginBtn.frame = CGRectMake(20, KScreenHeight-100, KScreenWidth-40, 40);
[_loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_loginBtn.titleLabel.font = [UIFont systemFontOfSize:17];
[_loginBtn addTarget:self action:@selector(logoutBtnAction) forControlEvents:UIControlEventTouchUpInside];
_loginBtn.titleLabel.font = [UIFont systemFontOfSize:18];
[_loginBtn setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal];
_loginBtn.layer.cornerRadius = 20;
_loginBtn.layer.masksToBounds = YES;
_loginBtn.layer.borderColor = [UIColor blackColor].CGColor;
_loginBtn.layer.borderWidth = 1;
}
return _loginBtn;
}
- (void)dealloc
{
_thirPartydView.delegate = nil;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end