添加隐私,注销功能
This commit is contained in:
@@ -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