Commit 9dec1e14 cgx

优化用户注销账号

1 个父辈 6167454c
......@@ -29,15 +29,17 @@ typedef NS_ENUM(NSInteger, DSResCode) {
+ (DSNetworkTool *)sharedManager;
///
/// @param params get、post请求统一使用post body
/// 第三方服务商Post请求
/// @param host 第三方主机地址
/// @param params 请求参数
/// @param view view
/// @param hasNetActivity 是否显示网络状态指示器
/// @param loadingInfo 网络加载信息
/// @param hasFailInfo 是否有失败信息
/// @param success success
/// @param failure failure
+ (__kindof NSURLSessionDataTask *)httpPostBodyRequestWithParam:(id)params
+ (__kindof NSURLSessionDataTask *)httpVendorPostRequestWithHost:(NSString *)host
params:(id)params
view:(UIView *)view
hasNetActivity:(BOOL)hasNetActivity
loadingInfo:(NSString *)loadingInfo
......
......@@ -29,7 +29,8 @@ NSString * const NetworkUnableError = @"网络不给力,请检查您的网络
return handle;
}
+ (__kindof NSURLSessionDataTask *)httpPostBodyRequestWithParam:(id)params
+ (__kindof NSURLSessionDataTask *)httpVendorPostRequestWithHost:(NSString *)host
params:(id)params
view:(UIView *)view
hasNetActivity:(BOOL)hasNetActivity
loadingInfo:(NSString *)loadingInfo
......@@ -42,37 +43,17 @@ NSString * const NetworkUnableError = @"网络不给力,请检查您的网络
view ? [DSProgressHUD showProgressHUDWithInfo:loadingInfo inView:view] : [DSProgressHUD showProgressHUDWithInfo:loadingInfo];
}
NSString *urlString = [APIURL stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
DSLog(@"请求链接:%@,业务参数:%@", urlString, params);
NSString *urlString = [host stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSMutableURLRequest *request = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:urlString parameters:nil error:nil];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error:nil];
[request setHTTPBody:jsonData];
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
DSLog(@"Vendor Post请求地址:%@,业务参数:%@", urlString, params);
NSURLSessionDataTask *dataTask = [[DSNetworkTool sharedManager] dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
if (loadingInfo) { [DSProgressHUD dissmissProgressHUD]; }
NSURLSessionDataTask *dataTask = [[DSNetworkTool sharedManager] POST:urlString parameters:params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
DSLog(@"responseObject:%@", responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
if (responseObject) {
NSDictionary *responseDic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
// DSLog(@"服务器返回的原始Json数据:%@", responseDic);
// 接口业务数据
NSDictionary *apiDataDic = [responseDic objectForKey:@"data"];
success(apiDataDic);
} else {
DSLog(@"失败错误信息:%@", error);
if (hasFailInfo) {
NSString *alertStr = [NSString stringWithFormat:@"%ld", error.code];
view ? [DSProgressHUD showDetailInfo:alertStr inView:view] : [DSProgressHUD showDetailInfo:alertStr];
}
failure(error);
}
}];
[dataTask resume];
return dataTask;
}
......
......@@ -123,14 +123,14 @@
[self startOpen];
// 注入js代码用于强制刷新小梦睡眠
NSString *jsCallBack = @"window.parent.location.reload()";
[self.aiWebView evaluateJavaScript:jsCallBack completionHandler:^(id _Nullable result, NSError * _Nullable error) {
[self.aiWebView loadRequest:self.request];
DSLog(@"注入成功...");
if (error) {
DSLog(@"err is %@", error.domain);
}
}];
// NSString *jsCallBack = @"window.parent.location.reload()";
// [self.aiWebView evaluateJavaScript:jsCallBack completionHandler:^(id _Nullable result, NSError * _Nullable error) {
// [self.aiWebView loadRequest:self.request];
// DSLog(@"注入成功...");
// if (error) {
// DSLog(@"err is %@", error.domain);
// }
// }];
}
}
}
......
......@@ -53,12 +53,6 @@
[DSProgressHUD dissmissProgressHUD];
if (requestModel.resCode == DSResCodeSuccess) {
[self clearUserData:@"退出成功"];
// 刷新我的个人信息相关数据
// 刷新主页数据
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateHomePage object:nil];
// 刷新AI睡眠教练
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateAICoach object:nil];
}
}];
}
......@@ -72,9 +66,6 @@
if (requestModel.resCode == DSResCodeSuccess) {
[self.closeAlertView dismissCloseUserAlertView];
[self clearUserData:@"注销成功"];
// 刷新我的个人信息相关数据
}
}];
}
......
......@@ -47,11 +47,8 @@
if (requestModel.resCode == DSResCodeSuccess) {
[DSProgressHUD showToast:@"登录成功"];
if (self.successBlock) {self.successBlock(); }
[LoginUtils updateDataNotiAfterLoginSuccess];
[self dismissViewControllerAnimated:YES completion:nil];
// 刷新主页数据
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateHomePage object:nil];
// 刷新AI睡眠教练
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateAICoach object:nil];
} else {
[DSProgressHUD showToast:requestModel.errorInfo];
}
......@@ -128,11 +125,8 @@
if (requestModel.resCode == DSResCodeSuccess) {
[DSProgressHUD showToast:@"登录成功"];
if (self.successBlock) {self.successBlock(); }
[LoginUtils updateDataNotiAfterLoginSuccess];
[self dismissViewControllerAnimated:YES completion:nil];
// 刷新主页数据
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateHomePage object:nil];
// 刷新AI睡眠教练
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateAICoach object:nil];
} else {
[DSProgressHUD showToast:requestModel.errorInfo];
}
......
......@@ -58,6 +58,9 @@ NS_ASSUME_NONNULL_BEGIN
/// @param target 入口控制器
/// @param sel 消息
+ (void)jumpToLoginControllerWithTarget:(UIViewController *)target selector:(SEL)sel;
/// 登录成功后更新数据通知
+ (void)updateDataNotiAfterLoginSuccess;
@end
NS_ASSUME_NONNULL_END
......@@ -80,8 +80,13 @@
+ (void)clearUserLoginData {
kUserDefaultsRemoveObj(UserBasicInfo);
// 发送更新用户数据显示UI通知
[[NSNotificationCenter defaultCenter] postNotificationName:HasUpdateUserDataNoti object:nil];
// 刷新主页数据
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateHomePage object:nil];
// 刷新AI睡眠教练
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateAICoach object:nil];
}
+ (void)jumpToLoginControllerWithTarget:(UIViewController *)target {
......@@ -107,4 +112,11 @@
}
}
+ (void)updateDataNotiAfterLoginSuccess {
// 刷新主页数据
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateHomePage object:nil];
// 刷新AI睡眠教练
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateAICoach object:nil];
}
@end
......@@ -33,6 +33,10 @@ NS_ASSUME_NONNULL_BEGIN
/// @param completion completion
+ (NSURLSessionDataTask *)closeUserRequestWithCompletion:(void (^)(UserRequestModel *requestModel))completion;
/// 撤销用户令牌接口(网页端用)
/// @param completion completion
+ (NSURLSessionDataTask *)revokeTokensRequestWithParams:(NSDictionary *)params completion:(void (^)(UserRequestModel *requestModel))completion;
/// 自动登录请求(用于更新token,登录成功后定期调用)
/// @param completion completion
+ (NSURLSessionDataTask *)autoLoginRequestWithCompletion:(void (^)(UserRequestModel *requestModel))completion;
......
......@@ -86,6 +86,16 @@
}];
}
+ (NSURLSessionDataTask *)revokeTokensRequestWithParams:(NSDictionary *)params completion:(void (^)(UserRequestModel *requestModel))completion
{
UserRequestModel * requestModel = [[UserRequestModel alloc] init];
return [self httpVendorPostRequestWithHost:@"https://appleid.apple.com/auth/revoke" params:params view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:YES success:^(NSDictionary *responseObj) {
} failure:^(id failureInfo) {
}];
}
+ (NSURLSessionDataTask *)autoLoginRequestWithCompletion:(void (^)(UserRequestModel *requestModel))completion {
UserRequestModel * requestModel = [[UserRequestModel alloc] init];
NSString *api = @"auto_login";
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!