98 lines
3.8 KiB
Objective-C
98 lines
3.8 KiB
Objective-C
//
|
|
// QXChangeNickViewController.m
|
|
// QXLive
|
|
//
|
|
// Created by 启星 on 2025/5/21.
|
|
//
|
|
|
|
#import "QXChangeNicknameViewController.h"
|
|
#import <ImSDK_Plus/ImSDK_Plus.h>
|
|
#import "QXMineNetwork.h"
|
|
@interface QXChangeNicknameViewController ()
|
|
@property (nonatomic,strong)UIView *bgView;
|
|
@property (nonatomic,strong)UITextField *textField;
|
|
@property (nonatomic,strong)UIButton *deleteBtn;
|
|
@end
|
|
|
|
@implementation QXChangeNicknameViewController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
// Do any additional setup after loading the view.
|
|
}
|
|
|
|
-(void)viewWillAppear:(BOOL)animated{
|
|
[super viewWillAppear:animated];
|
|
[self.navigationController setNavigationBarHidden:NO animated:YES];
|
|
}
|
|
-(void)setNavgationItems{
|
|
[super setNavgationItems];
|
|
self.navigationItem.title = QXText(@"修改昵称");
|
|
UIButton *btn = [[UIButton alloc] init];
|
|
[btn setTitle:QXText(@"保存") forState:(UIControlStateNormal)];
|
|
btn.titleLabel.font = [UIFont systemFontOfSize:14.f];
|
|
[btn setTitleColor:QXConfig.themeColor forState:(UIControlStateNormal)];
|
|
[btn addTarget:self action:@selector(saveAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
|
|
}
|
|
|
|
- (void)initSubViews{
|
|
self.bgView = [[UIView alloc] initWithFrame:CGRectMake(16, NavContentHeight+12, SCREEN_WIDTH-32, 44)];
|
|
self.bgView.backgroundColor = [UIColor whiteColor];
|
|
[self.bgView addRoundedCornersWithRadius:7];
|
|
[self.view addSubview:self.bgView];
|
|
|
|
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(12, 0, self.bgView.width-24-44, 44)];
|
|
self.textField.placeholder = QXText(@"请输入昵称");
|
|
self.textField.font = [UIFont systemFontOfSize:14];
|
|
self.textField.textColor = QXConfig.textColor;
|
|
[self.bgView addSubview:self.textField];
|
|
|
|
self.deleteBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.bgView.width-44, 0, 44, 44)];
|
|
[self.deleteBtn setImage:[UIImage imageNamed:@"Plus Circle"] forState:(UIControlStateNormal)];
|
|
[self.deleteBtn addTarget:self action:@selector(deleteAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|
[self.bgView addSubview:self.deleteBtn];
|
|
}
|
|
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
|
|
[self.view endEditing:YES];
|
|
}
|
|
-(void)deleteAction{
|
|
self.textField.text = @"";
|
|
}
|
|
-(void)saveAction{
|
|
[self.view endEditing:YES];
|
|
__block NSString *nickName = self.textField.text;
|
|
__block NSString *avatar = [QXGlobal shareGlobal].loginModel.avatar;
|
|
QXLOG(@"修改昵称%@",nickName);
|
|
MJWeakSelf
|
|
[QXMineNetwork editUserInfoWithNickname:nickName
|
|
birthday:@""
|
|
sex:@""
|
|
avatar:@""
|
|
images:@""
|
|
profile:@""
|
|
tag_id:@""
|
|
successBlock:^(NSDictionary * _Nonnull dict) {
|
|
/// 更新存储信息
|
|
[QXGlobal shareGlobal].loginModel.nickname = nickName;
|
|
[[QXGlobal shareGlobal] updateUserInfoWithMolde:[QXGlobal shareGlobal].loginModel];
|
|
|
|
/// 同步修改腾讯个人信息
|
|
V2TIMUserFullInfo *info = [[V2TIMUserFullInfo alloc] init];
|
|
info.faceURL = avatar;
|
|
info.nickName = nickName;
|
|
[[V2TIMManager sharedInstance] setSelfInfo:info succ:^{
|
|
QXLOG(@"腾讯IM同步个人信息成功");
|
|
} fail:^(int code, NSString * _Nullable desc) {
|
|
QXLOG(@"腾讯IM同步个人信息失败");
|
|
}];
|
|
showToast(QXText(@"修改成功"));
|
|
[weakSelf.navigationController popViewControllerAnimated:YES];
|
|
}
|
|
failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
showToast(msg);
|
|
}];
|
|
}
|
|
|
|
@end
|