添加隐私,注销功能
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#import "KBChangeNicknamePopView.h"
|
||||
#import "KBGenderPickerPopView.h"
|
||||
#import "KBMyVM.h"
|
||||
#import "KBAlert.h"
|
||||
@interface KBPersonInfoVC () <UITableViewDelegate, UITableViewDataSource, PHPickerViewControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate>
|
||||
|
||||
// 列表
|
||||
@@ -25,8 +26,10 @@
|
||||
@property (nonatomic, strong) UIButton *editBadge; // 头像右下角的小铅笔
|
||||
@property (nonatomic, strong) UILabel *modifyLabel; // “Modify” 文案
|
||||
|
||||
// 底部退出按钮(固定在屏幕底部)
|
||||
// 底部退出登录按钮
|
||||
@property (nonatomic, strong) UIButton *logoutBtn;
|
||||
// 底部注销账户按钮
|
||||
@property (nonatomic, strong) UIButton *cancelBtn;
|
||||
|
||||
// 数据
|
||||
@property (nonatomic, copy) NSArray<NSDictionary *> *items; // {title,value,arrow,copy}
|
||||
@@ -64,9 +67,18 @@
|
||||
// 表头
|
||||
self.tableView.tableHeaderView = self.headerView;
|
||||
|
||||
// 底部退出按钮固定在屏幕底部
|
||||
// 底部退出登录按钮
|
||||
[self.view addSubview:self.logoutBtn];
|
||||
[self.logoutBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.view).offset(16);
|
||||
make.right.equalTo(self.view).offset(-16);
|
||||
make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-(12 + 56 + 10));
|
||||
make.height.mas_equalTo(56);
|
||||
}];
|
||||
|
||||
// 底部注销账户按钮
|
||||
[self.view addSubview:self.cancelBtn];
|
||||
[self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.view).offset(16);
|
||||
make.right.equalTo(self.view).offset(-16);
|
||||
make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-12);
|
||||
@@ -75,7 +87,7 @@
|
||||
|
||||
// 列表底部腾出空间,避免被按钮挡住
|
||||
UIEdgeInsets inset = self.tableView.contentInset;
|
||||
inset.bottom = 56 + 24; // 按钮高度 + 额外间距
|
||||
inset.bottom = 56 + 10 + 56 + 24; // 两个按钮高度 + 间距 + 额外间距
|
||||
self.tableView.contentInset = inset;
|
||||
self.viewModel = [[KBMyVM alloc] init];
|
||||
__weak typeof(self) weakSelf = self;
|
||||
@@ -275,6 +287,25 @@
|
||||
[self.myVM logout];
|
||||
}
|
||||
|
||||
- (void)onTapCancelAccount {
|
||||
[[KBMaiPointReporter sharedReporter] reportClickWithEventName:@"click_person_cancel_account_btn"
|
||||
pageId:@"person_info"
|
||||
elementId:@"cancel_account_btn"
|
||||
extra:nil
|
||||
completion:nil];
|
||||
KBWeakSelf;
|
||||
[KBAlert confirmTitle:KBLocalized(@"Cancel Account")
|
||||
message:KBLocalized(@"After cancellation, your account will be deactivated and local login data will be cleared. Continue?")
|
||||
ok:KBLocalized(@"Confirm")
|
||||
cancel:KBLocalized(@"Cancel")
|
||||
okColor:[UIColor colorWithHex:0xFF0000]
|
||||
cancelColor:nil
|
||||
completion:^(BOOL ok) {
|
||||
if (!ok) { return; }
|
||||
[weakSelf.myVM cancelAccountWithCompletion:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - Lazy UI(懒加载)
|
||||
|
||||
- (UITableView *)tableView {
|
||||
@@ -378,6 +409,19 @@
|
||||
return _logoutBtn;
|
||||
}
|
||||
|
||||
- (UIButton *)cancelBtn {
|
||||
if (!_cancelBtn) {
|
||||
_cancelBtn = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
[_cancelBtn setTitle:KBLocalized(@"Cancel Account") forState:UIControlStateNormal];
|
||||
[_cancelBtn setTitleColor:[UIColor colorWithHex:0xFF0000] forState:UIControlStateNormal];
|
||||
_cancelBtn.titleLabel.font = [KBFont medium:16];
|
||||
_cancelBtn.backgroundColor = UIColor.whiteColor;
|
||||
_cancelBtn.layer.cornerRadius = 12; _cancelBtn.layer.masksToBounds = YES;
|
||||
[_cancelBtn addTarget:self action:@selector(onTapCancelAccount) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _cancelBtn;
|
||||
}
|
||||
|
||||
#pragma mark - Image Picker
|
||||
|
||||
- (void)presentImagePicker {
|
||||
|
||||
@@ -31,6 +31,7 @@ typedef void(^KBSubmitFeedbackCompletion)(BOOL success, NSError *_Nullable error
|
||||
typedef void(^KBMyPurchaseRecordCompletion)(NSArray<KBConsumptionRecord *> *_Nullable records, NSError *_Nullable error);
|
||||
typedef void(^KBMyInviteCodeCompletion)(KBInviteCodeModel *_Nullable inviteCode, NSError *_Nullable error);
|
||||
typedef void(^KBMyCustomerMailCompletion)(NSString *_Nullable customerMail, NSError *_Nullable error);
|
||||
typedef void(^KBCancelAccountCompletion)(BOOL success, NSError *_Nullable error);
|
||||
|
||||
@interface KBMyVM : NSObject
|
||||
|
||||
@@ -77,6 +78,9 @@ typedef void(^KBMyCustomerMailCompletion)(NSString *_Nullable customerMail, NSEr
|
||||
|
||||
/// 退出登录
|
||||
- (void)logout;
|
||||
|
||||
/// 注销账号(/user/cancelAccount)
|
||||
- (void)cancelAccountWithCompletion:(KBCancelAccountCompletion)completion;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@@ -457,18 +457,67 @@ NSString * const KBUserCharacterDeletedNotification = @"KBUserCharacterDeletedNo
|
||||
|
||||
NSString *message = jsonOrData[KBMessage] ?: KBLocalized(@"Success");
|
||||
[KBHUD showSuccess:message];
|
||||
|
||||
// 本地会话退出
|
||||
[[KBUserSessionManager shared] logout];
|
||||
|
||||
// 回到登录 / 主界面
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
id<UIApplicationDelegate> appDelegate = UIApplication.sharedApplication.delegate;
|
||||
if ([appDelegate respondsToSelector:@selector(toMainTabbarVC)]) {
|
||||
AppDelegate *delegate = (AppDelegate *)appDelegate;
|
||||
[delegate toMainTabbarVC];
|
||||
}
|
||||
});
|
||||
[self kb_clearLoginInfoAndRouteHome];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)cancelAccountWithCompletion:(KBCancelAccountCompletion)completion {
|
||||
[KBHUD show];
|
||||
[[KBNetworkManager shared] POST:API_USER_CANCEL_ACCOUNT
|
||||
jsonBody:nil
|
||||
headers:nil
|
||||
autoShowBusinessError:NO
|
||||
completion:^(NSDictionary *jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
[KBHUD dismiss];
|
||||
|
||||
if (error) {
|
||||
NSString *msg = KBBizMessageFromJSONObject(jsonOrData) ?: error.localizedDescription ?: KBLocalized(@"Network error");
|
||||
[KBHUD showInfo:msg];
|
||||
if (completion) {
|
||||
completion(NO, error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *message = jsonOrData[KBMessage] ?: KBLocalized(@"Success");
|
||||
[KBHUD showSuccess:message];
|
||||
|
||||
[self kb_clearLoginInfoAndRouteHome];
|
||||
if (completion) {
|
||||
completion(YES, nil);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
/// 清理本地登录态及关联缓存,并回到首页。
|
||||
- (void)kb_clearLoginInfoAndRouteHome {
|
||||
[[KBUserSessionManager shared] logout];
|
||||
|
||||
NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:AppGroup];
|
||||
NSArray<NSString *> *sharedKeys = @[
|
||||
AppGroup_MyKbJson,
|
||||
AppGroup_UserAvatarURL,
|
||||
AppGroup_SubscriptionPrefillPayload,
|
||||
AppGroup_ChatUpdatedCompanionId,
|
||||
@"AppGroup_SelectedPersona"
|
||||
];
|
||||
for (NSString *key in sharedKeys) {
|
||||
[sharedDefaults removeObjectForKey:key];
|
||||
}
|
||||
[sharedDefaults synchronize];
|
||||
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
[defaults removeObjectForKey:@"KBAISelectedPersonaId"];
|
||||
[defaults synchronize];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
id<UIApplicationDelegate> appDelegate = UIApplication.sharedApplication.delegate;
|
||||
if ([appDelegate respondsToSelector:@selector(toMainTabbarVC)]) {
|
||||
AppDelegate *delegate = (AppDelegate *)appDelegate;
|
||||
[delegate toMainTabbarVC];
|
||||
}
|
||||
});
|
||||
}
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user