LoginViewController.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // LoginViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/17.
  6. //
  7. #import "LoginViewController.h"
  8. #import "LoginBodyView.h"
  9. #import "VefiCodeLoginController.h"
  10. #import "PasswordLoginController.h"
  11. #import "KSBaseWKWebViewController.h"
  12. #import "UserInfoManager.h"
  13. #import "AppDelegate+AppService.h"
  14. @interface LoginViewController ()
  15. @property (nonatomic, strong) LoginBodyView *bodyView;
  16. @end
  17. @implementation LoginViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view.
  21. self.ks_prefersNavigationBarHidden = YES;
  22. [self configUI];
  23. }
  24. - (void)configUI {
  25. _bodyView = [LoginBodyView shareInstance];
  26. if (![NSString isEmptyString:UserDefault(PHONEKEY)]) {
  27. _bodyView.phoneField.text = UserDefault(PHONEKEY);
  28. }
  29. CGFloat height = KPortraitHeight;
  30. [self.scrollView addSubview:_bodyView];
  31. [_bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.top.mas_equalTo(self.scrollView.mas_top);
  33. make.right.left.mas_equalTo(self.view);
  34. make.height.mas_equalTo(height);
  35. }];
  36. MJWeakSelf;
  37. [_bodyView loginActionCallback:^(LOGINACTION action, NSString * _Nonnull phoneNo) {
  38. [weakSelf operationWithType:action phone:phoneNo];
  39. }];
  40. }
  41. - (void)operationWithType:(LOGINACTION)action phone:(NSString *)phone {
  42. switch (action) {
  43. case LOGINACTION_CODE:
  44. {
  45. if (![NSString isMobilePhoneNumber:phone]) {
  46. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"手机号码输入有误"];
  47. return;
  48. }
  49. VefiCodeLoginController *ctrl = [[VefiCodeLoginController alloc] init];
  50. ctrl.phoneNo = phone;
  51. [self.navigationController pushViewController:ctrl animated:YES];
  52. }
  53. break;
  54. case LOGINACTION_PASSWORD:
  55. {
  56. PasswordLoginController *ctrl = [[PasswordLoginController alloc] init];
  57. if (![NSString isEmptyString:phone]) {
  58. ctrl.phoneNo = phone;
  59. }
  60. [self.navigationController pushViewController:ctrl animated:YES];
  61. }
  62. break;
  63. case LOGINACTION_REGPROTOCAL: // 注册协议
  64. {
  65. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  66. webCtrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST, @"/#/registerProtocol"];
  67. [self.navigationController pushViewController:webCtrl animated:YES];
  68. }
  69. break;
  70. case LOGINACTION_PRIVACY: // 隐私协议
  71. {
  72. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  73. webCtrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST, @"/#/privacyProtocol"];
  74. [self.navigationController pushViewController:webCtrl animated:YES];
  75. }
  76. break;
  77. case LOGINACTION_VERSIONCHECK:
  78. {
  79. [self versionCheck];
  80. }
  81. break;
  82. default:
  83. break;
  84. }
  85. }
  86. - (void)versionCheck {
  87. NSString *currentVersion = [USER_MANAGER getCurrentVersion];
  88. NSString *storeUrl = @"https://apps.apple.com/cn/app/%E9%85%B7%E4%B9%90%E7%A7%80%E5%AD%A6%E9%99%A2/id1626971149?uo=4";
  89. [KSNetworkingManager appVersionInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  90. if ([dic ks_integerValueForKey:@"code"] == 200) {
  91. NSString *serviceVersion = [[dic ks_dictionaryValueForKey:@"data"] ks_stringValueForKey:@"version"];
  92. if ([currentVersion isEqualToString:serviceVersion]) {
  93. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"当前是最新版本"];
  94. }
  95. else if ([USER_MANAGER isLowerVersionCompareLocalVersion:currentVersion serviceVersion:serviceVersion]) {
  96. // desc
  97. NSString *descMessage = [[dic ks_dictionaryValueForKey:@"data"] ks_stringValueForKey:@"description"];
  98. if ([NSString isEmptyString:descMessage]) {
  99. descMessage = @"";
  100. }
  101. // 判断
  102. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  103. [parm setValue:serviceVersion forKey:@"memo"];
  104. [parm setValue:descMessage forKey:@"descMessage"];
  105. [parm setValue:storeUrl forKey:@"openUrl"];
  106. if ([[dic ks_dictionaryValueForKey:@"data"] ks_boolValueForKey:@"isForceUpdate"]) {
  107. [parm setValue:@(YES) forKey:@"isforce"];
  108. }
  109. else {
  110. [parm setValue:@(NO) forKey:@"isforce"];
  111. }
  112. [AppDelegate shareAppDelegate].messageDict = parm;
  113. [[AppDelegate shareAppDelegate] showMemoAlert];
  114. }
  115. else {
  116. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"当前是最新版本"];
  117. }
  118. }
  119. } faliure:^(NSError * _Nonnull error) {
  120. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"当前是最新版本"];
  121. }];
  122. }
  123. /*
  124. #pragma mark - Navigation
  125. // In a storyboard-based application, you will often want to do a little preparation before navigation
  126. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  127. // Get the new view controller using [segue destinationViewController].
  128. // Pass the selected object to the new view controller.
  129. }
  130. */
  131. @end