| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- //
- // MOLoginChooseVC.m
- // MiMoLive
- //
- // Created by SuperC on 2023/10/15.
- //
- #import "MOLoginChooseVC.h"
- #import "MOPwdAndSMSLoginVC.h"
- #if !TARGET_IPHONE_SIMULATOR
- #import <MOBFoundation/MobSDK+Privacy.h>
- #endif
- #import "MOFirstInfoSetVC.h"
- #import "MOWebViewController.h"
- #import "UIImage+YYAdd.h"
- #import <AdjustSdk/AdjustSdk.h>
- #import "TencentCaptcha.h"
- #import "MOLoginPhoneVC.h"
- #import "MOLoginManager.h"
- #import "MOUploadDeviceTool.h"
- @interface MOLoginChooseVC ()<WKNavigationDelegate>
- @property (weak, nonatomic) IBOutlet UIButton *phoneNumberBtn;
- @property (weak, nonatomic) IBOutlet BigBtn *agreeBtn;
- @property (weak, nonatomic) IBOutlet UILabel *tipLab;
- /** 是否同意协议, 默认没有同意 */
- @property (nonatomic, assign) BOOL isAgreeAM;
- @property (weak, nonatomic) IBOutlet UIImageView *logoImg;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *logoTop;
- @property (weak, nonatomic) IBOutlet UIStackView *stackView;
- @property (weak, nonatomic) IBOutlet UIImageView *centerImgView;
- @property (weak, nonatomic) IBOutlet UIImageView *bottomImgView;
- //第三方平台信息
- @property (nonatomic, copy) NSString *nickname;//昵称
- @property (nonatomic, copy) NSString *avatar;//头像
- @property (nonatomic, copy) NSString *headImgUrl;//上传头像成功后的url
- @end
- @implementation MOLoginChooseVC
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self.navigationController setNavigationBarHidden:YES animated:animated];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib.
-
- // self.isAgreeAM = NO;
- [self setupUI];
-
- // for (NSString *familyName in [UIFont familyNames]) {
- // MOLogV(@"Font family: %@", familyName);
- // NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName];
- // for (NSString *fontName in fontNames) {
- // MOLogV(@" Font name: %@", fontName);
- // }
- // }
-
- [self uploadPrivacyPermissionStatus];
-
- [[MOUploadDeviceTool shareTool] uploadDeviceInfo];
- }
- - (void)setupUI{
- self.phoneNumberBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
-
- NSArray *colorArr = @[kBaseColorLeft,kBaseColorRight];
- UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH - 24.0 * 2), 48.0) Colors:colorArr GradientType:0];
- [self.phoneNumberBtn setBackgroundImage:image forState:UIControlStateNormal];
- self.phoneNumberBtn.layer.cornerRadius = 12.0;
- self.phoneNumberBtn.layer.masksToBounds = YES;
-
- [self.phoneNumberBtn setTitle:NSLocalString(@"mimo_login_phone") forState:UIControlStateNormal];
- [self.phoneNumberBtn setFont:[MOTextTools poppinsSemiBoldFont:16]];
-
- NSArray *centerColorArr = @[[MOTools colorWithHexString:@"#EEF6FE" alpha:0.0],[MOTools colorWithHexString:@"#F7F8FC" alpha:1.0]];
- UIImage *centerImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, SCREENWIDTH, 124.0) Colors:centerColorArr GradientType:1];
- [self.centerImgView setImage:centerImage];
-
- NSArray *bottomColorArr = @[[MOTools colorWithHexString:@"#F7F8FB" alpha:1.0],[MOTools colorWithHexString:@"#F3F4FA" alpha:1.0]];
- UIImage *bottomImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, SCREENWIDTH, 257) Colors:bottomColorArr GradientType:1];
- [self.bottomImgView setImage:bottomImage];
-
- NSString *contentStr = [NSString stringWithFormat:@"%@%@%@",NSLocalString(@"mimo_agreement"),NSLocalString(@"mimo_agreement_service"),NSLocalString(@"mimo_agreement_privacy")];
- self.tipLab.attributedText = [self colorfulStringWith:contentStr ServiceStr:NSLocalString(@"mimo_agreement_service") Privacy:NSLocalString(@"mimo_agreement_privacy")];
- // self.tipLab.text = contentStr;
-
- // 向 UILabel 添加一个点击手势识别器
- UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
- self.tipLab.userInteractionEnabled = YES;
- [self.tipLab addGestureRecognizer:tapGesture];
-
- self.agreeBtn.selected = NO;
-
- self.logoTop.constant = kTopSafeAreaInset + 50;
- [self.logoImg setImage:[UIImage imageNamed:@"icon_login_logo_white"]];
-
- self.stackView.spacing = 5;
- }
- - (NSAttributedString *)colorfulStringWith:(NSString *)nameStr ServiceStr:(NSString *)serviceStr Privacy:(NSString *)privacyStr{
- // 创建属性字符串,整体颜色为白色
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:nameStr attributes:@{NSFontAttributeName:[MOTextTools regularFont:12],NSForegroundColorAttributeName: kBaseTextColor_3}];
-
- // 设置整段行高为 16
- NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- paragraphStyle.minimumLineHeight = 16;
- paragraphStyle.maximumLineHeight = 16;
- [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attributedString.length)];
-
- NSRange redRangeOne = [nameStr rangeOfString:serviceStr];
- if(redRangeOne.location != NSNotFound){
- // 将最后三个字符的颜色设置为红色
- [attributedString addAttribute:NSForegroundColorAttributeName value:[MOTools colorWithHexString:@"#4363FF"] range:redRangeOne];
- }
-
- NSRange redRangeTwo = [nameStr rangeOfString:privacyStr];
- if(redRangeTwo.location != NSNotFound){
- // 将最后三个字符的颜色设置为红色
- [attributedString addAttribute:NSForegroundColorAttributeName value:[MOTools colorWithHexString:@"#4363FF"] range:redRangeTwo];
- }
-
- return attributedString;
- }
- - (void)handleTap:(UITapGestureRecognizer *)gestureRecognizer {
- // 获取触摸点的位置
- CGPoint tapLocation = [gestureRecognizer locationInView:self.tipLab];
-
- // 获取点击的字符索引
- NSUInteger characterIndex = [self characterIndexForPoint:tapLocation inLabel:self.tipLab];
-
- NSString *contentStr = [NSString stringWithFormat:@"%@%@%@",NSLocalString(@"mimo_agreement"),NSLocalString(@"mimo_agreement_service"),NSLocalString(@"mimo_agreement_privacy")];
- NSRange redRangeOne = [contentStr rangeOfString:NSLocalString(@"mimo_agreement_service")];
- NSRange redRangeTwo = [contentStr rangeOfString:NSLocalString(@"mimo_agreement_privacy")];
-
- if (characterIndex >= redRangeOne.location && characterIndex <= redRangeOne.location + redRangeOne.length)
- {
- //第一个
- MOWebViewController *vc = [[MOWebViewController alloc] init];
- // NSString *urlStr = [NSString stringWithFormat:@"%@/#/userAgreement",kNetPath_Web_Base];
- NSString *urlStr = @"https://mimo-live.github.io/mimolive/user-agreement/yonghuxieyi.html";
- vc.isShowTitle = YES;
- vc.isHaveSafeTop = YES;
- vc.titleStr = @"User Agreement";
- vc.webUrl = [NSURL URLWithString:urlStr];
- [self.navigationController pushViewController:vc animated:YES];
- return;
- }
-
- if (characterIndex >= redRangeTwo.location && characterIndex <= redRangeTwo.location + redRangeTwo.length)
- {
- //第二个
- MOWebViewController *vc = [[MOWebViewController alloc] init];
- // NSString *urlStr = [NSString stringWithFormat:@"%@/#/privacyPolicy",kNetPath_Web_Base];
- NSString *urlStr = @"https://mimo-live.github.io/mimolive/privacy-policy/siyinzhengce.html";
- vc.isShowTitle = YES;
- vc.isHaveSafeTop = YES;
- vc.titleStr = @"Privacy Policy";
- vc.webUrl = [NSURL URLWithString:urlStr];
- [self.navigationController pushViewController:vc animated:YES];
- return;
- }
-
- }
- // 获取点击位置处的字符索引
- - (NSUInteger)characterIndexForPoint:(CGPoint)point inLabel:(UILabel *)label {
- // 创建一个容器 NSTextStorage
- NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString:label.attributedText];
- NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
- [textStorage addLayoutManager:layoutManager];
-
- // 创建一个容器 NSTextContainer
- NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:label.bounds.size];
- textContainer.lineFragmentPadding = 0;
- textContainer.maximumNumberOfLines = label.numberOfLines;
- textContainer.lineBreakMode = label.lineBreakMode;
- [layoutManager addTextContainer:textContainer];
-
- // 获取点击位置处的字符索引
- CGPoint textContainerOffset = CGPointMake((label.bounds.size.width - label.intrinsicContentSize.width) * 0.5, (label.bounds.size.height - label.intrinsicContentSize.height) * 0.5);
- CGPoint textPoint = CGPointMake(point.x - textContainerOffset.x, point.y - textContainerOffset.y);
- NSUInteger characterIndex = [layoutManager characterIndexForPoint:textPoint inTextContainer:textContainer fractionOfDistanceBetweenInsertionPoints:nil];
-
- return characterIndex;
- }
- - (void)setIsAgreeAM:(BOOL)isAgreeAM{
- _isAgreeAM = isAgreeAM;
-
- if(isAgreeAM){
- self.agreeBtn.selected = YES;
- }
- else{
- self.agreeBtn.selected = NO;
- }
- }
- //同意协议按钮点击
- - (IBAction)agreeBtnClick:(id)sender {
-
- self.isAgreeAM = !self.isAgreeAM;
-
- if(self.isAgreeAM){
- [self uploadPrivacyPermissionStatus];
- }
-
- }
- //手机号登录
- - (IBAction)phoneLoginClick:(id)sender {
-
- // if(!self.isAgreeAM){
- //
- // [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_common_agree_agreement")];
- // return;
- // }
- [self uploadPrivacyPermissionStatus];
-
- // MOPwdAndSMSLoginVC *vc = [[MOPwdAndSMSLoginVC alloc] init];
- MOLoginPhoneVC *vc = [[MOLoginPhoneVC alloc] init];
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (IBAction)appleLoginClick:(id)sender {
-
- // if(!self.isAgreeAM){
- // [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_common_agree_agreement")];
- // return;
- // }
- [self uploadPrivacyPermissionStatus];
-
- [[MOLoginManager shareManager] loginWithApple];
- }
- - (IBAction)facebookLoginClick:(id)sender {
-
- [self uploadPrivacyPermissionStatus];
-
- [[MOLoginManager shareManager] loginWithFacebook];
- }
- - (IBAction)googleLoginClick:(id)sender {
-
- [self uploadPrivacyPermissionStatus];
-
- [[MOLoginManager shareManager] loginWithGoogle];
- }
- ///MobSDK上传隐藏政策授权结果
- - (void)uploadPrivacyPermissionStatus{
- #if !TARGET_IPHONE_SIMULATOR
- [MobSDK uploadPrivacyPermissionStatus:YES onResult:^(BOOL success) {
-
- }];
- #endif
-
- //腾讯验证码 - 已同意隐私协议
- TencentCaptcha.userDidAcceptPrivacyPolicy = YES;
- }
- @end
|