MOLoginChooseVC.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. //
  2. // MOLoginChooseVC.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2023/10/15.
  6. //
  7. #import "MOLoginChooseVC.h"
  8. #import "MOPwdAndSMSLoginVC.h"
  9. #if !TARGET_IPHONE_SIMULATOR
  10. #import <MOBFoundation/MobSDK+Privacy.h>
  11. #endif
  12. #import "MOFirstInfoSetVC.h"
  13. #import "MOWebViewController.h"
  14. #import "UIImage+YYAdd.h"
  15. #import <AdjustSdk/AdjustSdk.h>
  16. #import "TencentCaptcha.h"
  17. #import "MOLoginPhoneVC.h"
  18. #import "MOLoginManager.h"
  19. #import "MOUploadDeviceTool.h"
  20. @interface MOLoginChooseVC ()<WKNavigationDelegate>
  21. @property (weak, nonatomic) IBOutlet UIButton *phoneNumberBtn;
  22. @property (weak, nonatomic) IBOutlet BigBtn *agreeBtn;
  23. @property (weak, nonatomic) IBOutlet UILabel *tipLab;
  24. /** 是否同意协议, 默认没有同意 */
  25. @property (nonatomic, assign) BOOL isAgreeAM;
  26. @property (weak, nonatomic) IBOutlet UIImageView *logoImg;
  27. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *logoTop;
  28. @property (weak, nonatomic) IBOutlet UIStackView *stackView;
  29. @property (weak, nonatomic) IBOutlet UIImageView *centerImgView;
  30. @property (weak, nonatomic) IBOutlet UIImageView *bottomImgView;
  31. //第三方平台信息
  32. @property (nonatomic, copy) NSString *nickname;//昵称
  33. @property (nonatomic, copy) NSString *avatar;//头像
  34. @property (nonatomic, copy) NSString *headImgUrl;//上传头像成功后的url
  35. @end
  36. @implementation MOLoginChooseVC
  37. - (void)viewWillAppear:(BOOL)animated{
  38. [super viewWillAppear:animated];
  39. [self.navigationController setNavigationBarHidden:YES animated:animated];
  40. }
  41. - (void)viewDidLoad {
  42. [super viewDidLoad];
  43. // Do any additional setup after loading the view from its nib.
  44. // self.isAgreeAM = NO;
  45. [self setupUI];
  46. // for (NSString *familyName in [UIFont familyNames]) {
  47. // MOLogV(@"Font family: %@", familyName);
  48. // NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName];
  49. // for (NSString *fontName in fontNames) {
  50. // MOLogV(@" Font name: %@", fontName);
  51. // }
  52. // }
  53. [self uploadPrivacyPermissionStatus];
  54. [[MOUploadDeviceTool shareTool] uploadDeviceInfo];
  55. }
  56. - (void)setupUI{
  57. self.phoneNumberBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
  58. NSArray *colorArr = @[kBaseColorLeft,kBaseColorRight];
  59. UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH - 24.0 * 2), 48.0) Colors:colorArr GradientType:0];
  60. [self.phoneNumberBtn setBackgroundImage:image forState:UIControlStateNormal];
  61. self.phoneNumberBtn.layer.cornerRadius = 12.0;
  62. self.phoneNumberBtn.layer.masksToBounds = YES;
  63. [self.phoneNumberBtn setTitle:NSLocalString(@"mimo_login_phone") forState:UIControlStateNormal];
  64. [self.phoneNumberBtn setFont:[MOTextTools poppinsSemiBoldFont:16]];
  65. NSArray *centerColorArr = @[[MOTools colorWithHexString:@"#EEF6FE" alpha:0.0],[MOTools colorWithHexString:@"#F7F8FC" alpha:1.0]];
  66. UIImage *centerImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, SCREENWIDTH, 124.0) Colors:centerColorArr GradientType:1];
  67. [self.centerImgView setImage:centerImage];
  68. NSArray *bottomColorArr = @[[MOTools colorWithHexString:@"#F7F8FB" alpha:1.0],[MOTools colorWithHexString:@"#F3F4FA" alpha:1.0]];
  69. UIImage *bottomImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, SCREENWIDTH, 257) Colors:bottomColorArr GradientType:1];
  70. [self.bottomImgView setImage:bottomImage];
  71. NSString *contentStr = [NSString stringWithFormat:@"%@%@%@",NSLocalString(@"mimo_agreement"),NSLocalString(@"mimo_agreement_service"),NSLocalString(@"mimo_agreement_privacy")];
  72. self.tipLab.attributedText = [self colorfulStringWith:contentStr ServiceStr:NSLocalString(@"mimo_agreement_service") Privacy:NSLocalString(@"mimo_agreement_privacy")];
  73. // self.tipLab.text = contentStr;
  74. // 向 UILabel 添加一个点击手势识别器
  75. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
  76. self.tipLab.userInteractionEnabled = YES;
  77. [self.tipLab addGestureRecognizer:tapGesture];
  78. self.agreeBtn.selected = NO;
  79. self.logoTop.constant = kTopSafeAreaInset + 50;
  80. [self.logoImg setImage:[UIImage imageNamed:@"icon_login_logo_white"]];
  81. self.stackView.spacing = 5;
  82. }
  83. - (NSAttributedString *)colorfulStringWith:(NSString *)nameStr ServiceStr:(NSString *)serviceStr Privacy:(NSString *)privacyStr{
  84. // 创建属性字符串,整体颜色为白色
  85. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:nameStr attributes:@{NSFontAttributeName:[MOTextTools regularFont:12],NSForegroundColorAttributeName: kBaseTextColor_3}];
  86. // 设置整段行高为 16
  87. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  88. paragraphStyle.minimumLineHeight = 16;
  89. paragraphStyle.maximumLineHeight = 16;
  90. [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attributedString.length)];
  91. NSRange redRangeOne = [nameStr rangeOfString:serviceStr];
  92. if(redRangeOne.location != NSNotFound){
  93. // 将最后三个字符的颜色设置为红色
  94. [attributedString addAttribute:NSForegroundColorAttributeName value:[MOTools colorWithHexString:@"#4363FF"] range:redRangeOne];
  95. }
  96. NSRange redRangeTwo = [nameStr rangeOfString:privacyStr];
  97. if(redRangeTwo.location != NSNotFound){
  98. // 将最后三个字符的颜色设置为红色
  99. [attributedString addAttribute:NSForegroundColorAttributeName value:[MOTools colorWithHexString:@"#4363FF"] range:redRangeTwo];
  100. }
  101. return attributedString;
  102. }
  103. - (void)handleTap:(UITapGestureRecognizer *)gestureRecognizer {
  104. // 获取触摸点的位置
  105. CGPoint tapLocation = [gestureRecognizer locationInView:self.tipLab];
  106. // 获取点击的字符索引
  107. NSUInteger characterIndex = [self characterIndexForPoint:tapLocation inLabel:self.tipLab];
  108. NSString *contentStr = [NSString stringWithFormat:@"%@%@%@",NSLocalString(@"mimo_agreement"),NSLocalString(@"mimo_agreement_service"),NSLocalString(@"mimo_agreement_privacy")];
  109. NSRange redRangeOne = [contentStr rangeOfString:NSLocalString(@"mimo_agreement_service")];
  110. NSRange redRangeTwo = [contentStr rangeOfString:NSLocalString(@"mimo_agreement_privacy")];
  111. if (characterIndex >= redRangeOne.location && characterIndex <= redRangeOne.location + redRangeOne.length)
  112. {
  113. //第一个
  114. MOWebViewController *vc = [[MOWebViewController alloc] init];
  115. // NSString *urlStr = [NSString stringWithFormat:@"%@/#/userAgreement",kNetPath_Web_Base];
  116. NSString *urlStr = @"https://mimo-live.github.io/mimolive/user-agreement/yonghuxieyi.html";
  117. vc.isShowTitle = YES;
  118. vc.isHaveSafeTop = YES;
  119. vc.titleStr = @"User Agreement";
  120. vc.webUrl = [NSURL URLWithString:urlStr];
  121. [self.navigationController pushViewController:vc animated:YES];
  122. return;
  123. }
  124. if (characterIndex >= redRangeTwo.location && characterIndex <= redRangeTwo.location + redRangeTwo.length)
  125. {
  126. //第二个
  127. MOWebViewController *vc = [[MOWebViewController alloc] init];
  128. // NSString *urlStr = [NSString stringWithFormat:@"%@/#/privacyPolicy",kNetPath_Web_Base];
  129. NSString *urlStr = @"https://mimo-live.github.io/mimolive/privacy-policy/siyinzhengce.html";
  130. vc.isShowTitle = YES;
  131. vc.isHaveSafeTop = YES;
  132. vc.titleStr = @"Privacy Policy";
  133. vc.webUrl = [NSURL URLWithString:urlStr];
  134. [self.navigationController pushViewController:vc animated:YES];
  135. return;
  136. }
  137. }
  138. // 获取点击位置处的字符索引
  139. - (NSUInteger)characterIndexForPoint:(CGPoint)point inLabel:(UILabel *)label {
  140. // 创建一个容器 NSTextStorage
  141. NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString:label.attributedText];
  142. NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
  143. [textStorage addLayoutManager:layoutManager];
  144. // 创建一个容器 NSTextContainer
  145. NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:label.bounds.size];
  146. textContainer.lineFragmentPadding = 0;
  147. textContainer.maximumNumberOfLines = label.numberOfLines;
  148. textContainer.lineBreakMode = label.lineBreakMode;
  149. [layoutManager addTextContainer:textContainer];
  150. // 获取点击位置处的字符索引
  151. CGPoint textContainerOffset = CGPointMake((label.bounds.size.width - label.intrinsicContentSize.width) * 0.5, (label.bounds.size.height - label.intrinsicContentSize.height) * 0.5);
  152. CGPoint textPoint = CGPointMake(point.x - textContainerOffset.x, point.y - textContainerOffset.y);
  153. NSUInteger characterIndex = [layoutManager characterIndexForPoint:textPoint inTextContainer:textContainer fractionOfDistanceBetweenInsertionPoints:nil];
  154. return characterIndex;
  155. }
  156. - (void)setIsAgreeAM:(BOOL)isAgreeAM{
  157. _isAgreeAM = isAgreeAM;
  158. if(isAgreeAM){
  159. self.agreeBtn.selected = YES;
  160. }
  161. else{
  162. self.agreeBtn.selected = NO;
  163. }
  164. }
  165. //同意协议按钮点击
  166. - (IBAction)agreeBtnClick:(id)sender {
  167. self.isAgreeAM = !self.isAgreeAM;
  168. if(self.isAgreeAM){
  169. [self uploadPrivacyPermissionStatus];
  170. }
  171. }
  172. //手机号登录
  173. - (IBAction)phoneLoginClick:(id)sender {
  174. // if(!self.isAgreeAM){
  175. //
  176. // [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_common_agree_agreement")];
  177. // return;
  178. // }
  179. [self uploadPrivacyPermissionStatus];
  180. // MOPwdAndSMSLoginVC *vc = [[MOPwdAndSMSLoginVC alloc] init];
  181. MOLoginPhoneVC *vc = [[MOLoginPhoneVC alloc] init];
  182. [self.navigationController pushViewController:vc animated:YES];
  183. }
  184. - (IBAction)appleLoginClick:(id)sender {
  185. // if(!self.isAgreeAM){
  186. // [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_common_agree_agreement")];
  187. // return;
  188. // }
  189. [self uploadPrivacyPermissionStatus];
  190. [[MOLoginManager shareManager] loginWithApple];
  191. }
  192. - (IBAction)facebookLoginClick:(id)sender {
  193. [self uploadPrivacyPermissionStatus];
  194. [[MOLoginManager shareManager] loginWithFacebook];
  195. }
  196. - (IBAction)googleLoginClick:(id)sender {
  197. [self uploadPrivacyPermissionStatus];
  198. [[MOLoginManager shareManager] loginWithGoogle];
  199. }
  200. ///MobSDK上传隐藏政策授权结果
  201. - (void)uploadPrivacyPermissionStatus{
  202. #if !TARGET_IPHONE_SIMULATOR
  203. [MobSDK uploadPrivacyPermissionStatus:YES onResult:^(BOOL success) {
  204. }];
  205. #endif
  206. //腾讯验证码 - 已同意隐私协议
  207. TencentCaptcha.userDidAcceptPrivacyPolicy = YES;
  208. }
  209. @end