SettingViewController.m 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. //
  2. // SettingViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/21.
  6. //
  7. #import "SettingViewController.h"
  8. #import "SettingBodyView.h"
  9. #import "KSBaseWKWebViewController.h"
  10. #import "FeedbackViewController.h"
  11. #import "AboutUsViewController.h"
  12. #import "UserInfoManager.h"
  13. #import "AddressListViewController.h"
  14. #import "UserAuthViewController.h"
  15. #import "LoginViewController.h"
  16. #import "AppDelegate.h"
  17. #import "CustomNavViewController.h"
  18. #import "JPUSHService.h"
  19. #import "AccountDeleteViewController.h"
  20. #import "UnbindTenantViewController.h"
  21. #import "TenantUnbindDetailViewController.h"
  22. #import "CoursewareDownloadManager.h"
  23. @interface SettingViewController ()
  24. @property (nonatomic, strong) SettingBodyView *bodyView;
  25. @property (nonatomic, strong) NSString *userSex;
  26. @end
  27. @implementation SettingViewController
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. // Do any additional setup after loading the view.
  31. [self allocTitle:@"设置"];
  32. [self configUI];
  33. }
  34. - (void)viewWillAppear:(BOOL)animated {
  35. [super viewWillAppear:animated];
  36. [self requestUserMemo];
  37. }
  38. - (void)requestUserMemo {
  39. [[UserInfoManager shareInstance] requsetconfigCallback:^(BOOL success) {
  40. [self refreshBodyView:success];
  41. }];
  42. }
  43. - (void)refreshBodyView:(BOOL)isMember {
  44. self.bodyView.isMember = isMember;
  45. }
  46. - (void)configUI {
  47. [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
  48. make.left.right.mas_equalTo(self.view);
  49. make.top.mas_equalTo(self.view.mas_top);
  50. make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin);
  51. }];
  52. self.bodyView = [SettingBodyView shareInstance];
  53. CGFloat viewHeight = KPortraitHeight - kNaviBarHeight - iPhoneXSafeBottomMargin;
  54. [self.scrollView addSubview:self.bodyView];
  55. [self.bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.top.mas_equalTo(self.scrollView.mas_top);
  57. make.right.left.mas_equalTo(self.view);
  58. make.height.mas_equalTo(viewHeight);
  59. }];
  60. [self.scrollView setContentSize:CGSizeMake(kScreenWidth, viewHeight)];
  61. KSWeakSelf(weakSelf);
  62. [self.bodyView settingAction:^(SETTINGACTION type) {
  63. [weakSelf operationAction:type];
  64. }];
  65. }
  66. - (void)operationAction:(SETTINGACTION)type {
  67. switch (type) {
  68. case SETTINGACTION_ADDRESS:
  69. {
  70. AddressListViewController *ctrl = [[AddressListViewController alloc] init];
  71. [self.navigationController pushViewController:ctrl animated:YES];
  72. }
  73. break;
  74. case SETTINGACTION_ONLINECHECK:
  75. {
  76. }
  77. break;
  78. case SETTINGACTION_PRIVACY:
  79. {
  80. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  81. webCtrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST, @"/#/privacyProtocol"];
  82. [self.navigationController pushViewController:webCtrl animated:YES];
  83. }
  84. break;
  85. case SETTINGACTION_FEEEDBACK:
  86. {
  87. FeedbackViewController *ctrl = [[FeedbackViewController alloc] init];
  88. [self.navigationController pushViewController:ctrl animated:YES];
  89. }
  90. break;
  91. case SETTINGACTION_ABOUTUS:
  92. {
  93. AboutUsViewController *aboutUs = [[AboutUsViewController alloc] init];
  94. [self.navigationController pushViewController:aboutUs animated:YES];
  95. }
  96. break;
  97. case SETTINGACTION_LOGOUT:
  98. {
  99. [self logoutAction];
  100. }
  101. break;
  102. case SETTINGACTION_DELETEACCOUNT:
  103. {
  104. [self toDelteAccountView];
  105. }
  106. break;
  107. case SETTINGACTION_MUSICCHECK:
  108. {
  109. // /#/review-list
  110. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  111. ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST, @"/#/review-list"];
  112. [self.navigationController pushViewController:ctrl animated:YES];
  113. }
  114. break;
  115. case SETTINGACTION_UNBIND:
  116. {
  117. [self checkUnbindStatus];
  118. }
  119. break;
  120. case SETTINGACTION_CLEARCACHE:
  121. {
  122. [self clearCache];
  123. }
  124. break;
  125. default:
  126. break;
  127. }
  128. }
  129. - (void)clearCache {
  130. [VoNetworking clearDownloadData];
  131. if (COURSEWARE_MANAGER.isDownloading) { // 如果在下载 取消
  132. [COURSEWARE_MANAGER cancleDownloadCourseware];
  133. }
  134. NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
  135. NSString *bundlePath = [documentsPath stringByAppendingPathComponent:@"CoursewarePath"];
  136. NSFileManager *fileManager = [NSFileManager defaultManager];
  137. BOOL isExist = [fileManager fileExistsAtPath:bundlePath];
  138. BOOL isSuccessClearCourseware = NO;
  139. if (isExist) {
  140. isSuccessClearCourseware = [fileManager removeItemAtPath:bundlePath error:nil];
  141. }
  142. else {
  143. isSuccessClearCourseware = YES;
  144. }
  145. NSString *accompanyCachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
  146. NSString *accompanyFilePath= [accompanyCachePath stringByAppendingPathComponent:@"AccompanySong"];
  147. BOOL isAccompanySongExist = [fileManager fileExistsAtPath:accompanyFilePath];
  148. BOOL isSuccessClearAccompany = NO;
  149. if (isAccompanySongExist) {
  150. isSuccessClearAccompany = [fileManager removeItemAtPath:accompanyFilePath error:nil];
  151. }
  152. else {
  153. isSuccessClearAccompany = YES;
  154. }
  155. if (isSuccessClearCourseware && isSuccessClearAccompany) {
  156. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"清理完成"];
  157. }
  158. }
  159. /**
  160. */
  161. - (void)checkUnbindStatus {
  162. [LOADING_MANAGER showHUD];
  163. [KSNetworkingManager unbindTenantDetailRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  164. [LOADING_MANAGER removeHUD];
  165. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  166. NSDictionary *parm = [dic ks_dictionaryValueForKey:@"data"];
  167. if (parm) {
  168. NSString *reson = [parm ks_stringValueForKey:@"unbindReason"];
  169. [self showUnbindDetail:reson tenantName:[parm ks_stringValueForKey:@"tenantName"]];
  170. }
  171. else {
  172. [self toUnbindTenantView];
  173. }
  174. }
  175. else {
  176. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  177. }
  178. } faliure:^(NSError * _Nonnull error) {
  179. [LOADING_MANAGER removeHUD];
  180. }];
  181. }
  182. - (void)toUnbindTenantView {
  183. UnbindTenantViewController *ctrl = [[UnbindTenantViewController alloc] init];
  184. [self.navigationController pushViewController:ctrl animated:YES];
  185. }
  186. - (void)showUnbindDetail:(NSString *)reson tenantName:(NSString *)tenantName {
  187. TenantUnbindDetailViewController *ctrl = [[TenantUnbindDetailViewController alloc] init];
  188. [ctrl configTenantName:tenantName desc:reson];
  189. [self.navigationController pushViewController:ctrl animated:YES];
  190. }
  191. - (void)toDelteAccountView {
  192. AccountDeleteViewController *detailView = [[AccountDeleteViewController alloc] init];
  193. [self.navigationController pushViewController:detailView animated:YES];
  194. }
  195. - (void)logoutAction {
  196. [KSNetworkingManager logoutRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  197. [self clearSource];
  198. } faliure:^(NSError * _Nonnull error) {
  199. [self clearSource];
  200. }];
  201. }
  202. - (void)clearSource {
  203. [APPLOGIN_MANAGER logoutActionWithMsg:@""];
  204. }
  205. /*
  206. #pragma mark - Navigation
  207. // In a storyboard-based application, you will often want to do a little preparation before navigation
  208. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  209. // Get the new view controller using [segue destinationViewController].
  210. // Pass the selected object to the new view controller.
  211. }
  212. */
  213. @end