| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572 |
- //
- // MOPwdAndSMSLoginVC.m
- // MiMoLive
- //
- // Created by SuperC on 2023/10/15.
- //
- #import "MOPwdAndSMSLoginVC.h"
- #import "MOSelectPartitionVC.h"
- #import "MOSetPasswordSMS.h"
- #import "NSString+YYAdd.h"
- #import "MOFirstInfoSetVC.h"
- #import "MOCountDownButton.h"
- #import "UIImage+YYAdd.h"
- #import <AdjustSdk/AdjustSdk.h>
- #import "TencentCaptcha.h"
- #import <WebKit/WebKit.h>
- @interface MOPwdAndSMSLoginVC ()<WKNavigationDelegate>
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *backTop;
- @property (weak, nonatomic) IBOutlet UIImageView *bgImgView;
- @property (weak, nonatomic) IBOutlet UIImageView *topLogoImg;
- /** 提示标题 */
- @property (weak, nonatomic) IBOutlet UILabel *tipsLab;
- /** 手机号背景 */
- @property (weak, nonatomic) IBOutlet UIView *mobileBgView;
- /** 选择国家按钮 (+86) */
- @property (weak, nonatomic) IBOutlet UIButton *chooseCountryBtn;
- /** 手机号输入框 */
- @property (weak, nonatomic) IBOutlet UITextField *mobileTef;
- /** sms背景 */
- @property (weak, nonatomic) IBOutlet UIView *smsBgView;
- /** sms验证码输入框 */
- @property (weak, nonatomic) IBOutlet UITextField *smsTef;
- /** 帮助提示语 */
- @property (weak, nonatomic) IBOutlet UILabel *helpLab;
- /** 登录按钮 */
- @property (weak, nonatomic) IBOutlet UIButton *loginBtn;
- /** 更换登录方式 */
- @property (weak, nonatomic) IBOutlet UIButton *changeTypBtn;
- /** 密码输入背景view */
- @property (weak, nonatomic) IBOutlet UIView *pswBgView;
- /** 密码输入框 */
- @property (weak, nonatomic) IBOutlet UITextField *pswTef;
- @property (weak, nonatomic) IBOutlet UIButton *forgetBtn;
- @property (nonatomic, strong) MOCountDownButton *smsBtn;
- @property (weak, nonatomic) IBOutlet UILabel *codeTipLab;
- @property (weak, nonatomic) IBOutlet UILabel *pswTipLab;
- /** 当前界面是否是密码输入的状态 */
- @property (nonatomic, assign) BOOL isPsw;
- /** 是否越狱 */
- @property (nonatomic, assign) BOOL isRootMobile;
- /** 是否虚拟设备 */
- @property (nonatomic, assign) BOOL isVirtual;
- @property (nonatomic, strong) WKWebView *webView;
- @property (nonatomic, strong) UIView *webBgView;
- @end
- @implementation MOPwdAndSMSLoginVC
- - (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.isPsw = NO;
-
- [self setupUI];
-
- self.isRootMobile = [SecurityBridge isJailbroken];//是否越狱
- self.isVirtual = [SecurityBridge isRunningInEmulator];//是否虚拟机
- }
- - (void)setupUI{
-
- [self.chooseCountryBtn setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
- [self.mobileTef setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
- [self.tipsLab setFont:[MOTextTools getTheFontWithSize:24.0 AndFontName:kNormalContentFontStr]];
- [self.codeTipLab setFont:[MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr]];
- [self.smsTef setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
- [self.pswTipLab setFont:[MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr]];
- [self.pswTef setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
- [self.helpLab setFont:[MOTextTools getTheFontWithSize:10.0 AndFontName:kNormalContentFontStr]];
- [self.loginBtn setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
- [self.changeTypBtn setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
- [self.forgetBtn setFont:[MOTextTools getTheFontWithSize:11.0 AndFontName:kNormalContentFontStr]];
-
- CGFloat statusBarHeight = STATUS_BAR_HEIGHT;
- self.backTop.constant = statusBarHeight + 12.0;
-
- NSArray *colorArr = @[[MOTools colorWithHexString:@"#EDF1FD" alpha:1.0],[MOTools colorWithHexString:@"#FAFAFC" alpha:1.0]];
- UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT) Colors:colorArr GradientType:1];
- [self.bgImgView setImage:image];
-
- [self.topLogoImg setImage:[[UIImage imageNamed:@"icon_login_logo_white"] imageByTintColor:[MOTools colorWithHexString:@"#49C1FF" alpha:1.0]]];
-
- [self.smsBgView addSubview:self.smsBtn];
- [self.smsBtn mas_makeConstraints:^(MASConstraintMaker *make)
- {
- make.centerY.equalTo(self.smsBgView.mas_centerY);
- make.right.offset(-5.0);
- make.width.mas_greaterThanOrEqualTo(80);
- make.height.mas_equalTo(35);
- }];
-
- // self.mobileBgView.layer.cornerRadius = 50.0 / 2.0;
- // self.mobileBgView.layer.masksToBounds = YES;
- // self.mobileBgView.layer.borderWidth = 0.5;
- // self.mobileBgView.layer.borderColor = [MOTools colorWithHexString:@"#E5D7E3" alpha:0.5].CGColor;
- //修改placeHolder的颜色
- NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_login_hint_phone") attributes:@{NSForegroundColorAttributeName : [MOTools colorWithHexString:@"#E5D7E3" alpha:0.5]}];
- self.mobileTef.attributedPlaceholder = placeholderString;
-
- // self.smsBgView.layer.cornerRadius = 50.0 / 2.0;
- // self.smsBgView.layer.masksToBounds = YES;
- // self.smsBgView.layer.borderWidth = 0.5;
- // self.smsBgView.layer.borderColor = [MOTools colorWithHexString:@"#E5D7E3" alpha:0.5].CGColor;
- //修改placeHolder的颜色
- placeholderString = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_login_hint_verify_code") attributes:@{NSForegroundColorAttributeName : [MOTools colorWithHexString:@"#E5D7E3" alpha:0.5]}];
- self.smsTef.attributedPlaceholder = placeholderString;
-
- // self.pswBgView.layer.cornerRadius = 50.0 / 2.0;
- // self.pswBgView.layer.masksToBounds = YES;
- // self.pswBgView.layer.borderWidth = 0.5;
- // self.pswBgView.layer.borderColor = [MOTools colorWithHexString:@"#E5D7E3" alpha:0.5].CGColor;
- placeholderString = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_login_hint_password") attributes:@{NSForegroundColorAttributeName : [MOTools colorWithHexString:@"#E5D7E3" alpha:0.5]}];
- //修改placeHolder的颜色
- self.pswTef.attributedPlaceholder = placeholderString;
-
- NSArray *loginColorArr = @[kBaseColorLeft,kBaseColorRight];
- UIImage *loginImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH - 30.0 * 2), 60.0) Colors:loginColorArr GradientType:0];
- [self.loginBtn setBackgroundImage:loginImage forState:UIControlStateNormal];
- self.loginBtn.layer.cornerRadius = 60.0 / 2.0;
- self.loginBtn.layer.masksToBounds = YES;
-
- self.tipsLab.text = NSLocalString(@"mimo_login_sms");
- [self.loginBtn setTitle:NSLocalString(@"mimo_login") forState:UIControlStateNormal];
- [self.changeTypBtn setTitle:NSLocalString(@"mimo_login_pwd") forState:UIControlStateNormal];
- [self.forgetBtn setTitle:NSLocalString(@"mimo_login_forget") forState:UIControlStateNormal];
- self.helpLab.text = NSLocalString(@"mimo_login_hint_register_tip");
-
- self.smsTef.keyboardType = UIKeyboardTypeNumberPad;
- // self.smsTef.secureTextEntry = YES;
-
- self.pswTef.keyboardType = UIKeyboardTypeDefault;
- self.pswTef.secureTextEntry = YES;
-
-
- self.chooseCountryBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
- self.chooseCountryBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 0);
- self.chooseCountryBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 8);
-
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_login_forget") attributes:@{NSFontAttributeName:[MOTextTools getTheFontWithSize:11.0 AndFontName:kNormalContentFontStr],NSForegroundColorAttributeName: [MOTools colorWithHexString:@"#727272" alpha:1.0],NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle)}];
- self.forgetBtn.titleLabel.attributedText = attributedString;
- self.forgetBtn.hidden = YES;
- }
- - (void)setIsPsw:(BOOL)isPsw{
- _isPsw = isPsw;
-
- if(isPsw){
- //密码登录
- self.smsBgView.hidden = YES;
- self.pswBgView.hidden = NO;
- self.forgetBtn.hidden = NO;
-
- self.tipsLab.text = NSLocalString(@"mimo_login_pwd");
- [self.changeTypBtn setTitle:NSLocalString(@"mimo_login_sms") forState:UIControlStateNormal];
- self.helpLab.hidden = YES;
- }
- else{
- //验证码登录
- self.smsBgView.hidden = NO;
- self.pswBgView.hidden = YES;
- self.forgetBtn.hidden = YES;
-
- self.tipsLab.text = NSLocalString(@"mimo_login_sms");
- [self.changeTypBtn setTitle:NSLocalString(@"mimo_login_pwd") forState:UIControlStateNormal];
-
- self.helpLab.hidden = NO;
-
- }
- }
- - (IBAction)chooseCountryClick:(id)sender {
- MOSelectPartitionVC *vc = [[MOSelectPartitionVC alloc] init];
-
- //MARK: 选择区号回调
- WEAKSELF
- vc.selectCellBlock = ^(MOCountryList * _Nonnull model) {
- __strong typeof(weakSelf) self = weakSelf;
- [self.chooseCountryBtn setTitle:model.num forState:UIControlStateNormal];
- };
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (IBAction)backBtnClick:(id)sender {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (IBAction)forgetBtnClick:(id)sender {
- if(self.mobileTef.text.length == 0)
- {
- [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_phone")];
- return;
- }
-
- MOSetPasswordSMS *vc = [[MOSetPasswordSMS alloc] init];
- vc.code = self.chooseCountryBtn.titleLabel.text;
- vc.num = self.mobileTef.text;
- vc.vcType = MOEnterCodePasswordType;
- [self.navigationController pushViewController:vc animated:YES];
- }
- -(void)sendSmsClickAndBlock:(void (^)(BOOL isSuccess))block{
-
- if(self.mobileTef.text.length == 0)
- {
- [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_phone")];
- return;
- }
-
- [MBProgressHUD showActivityMessageInView:@""];
- WEAKSELF
- NSDictionary *dic = @{@"code":self.chooseCountryBtn.titleLabel.text,
- @"num":self.mobileTef.text};
- [kHttpManager loginAndGetMobileCodeWithParams:dic andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
-
- [MBProgressHUD hideHUD];
-
- if(kCode_Success){
- [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_verify_code")];
- [weakSelf.smsTef becomeFirstResponder];
- block ? block(YES) : nil;
- }
- else{
- kShowNetError(data)
- block ? block(NO) : nil;
- }
- }];
- }
- //登录按钮点击
- - (IBAction)loginBtnClick:(id)sender {
-
- if(self.isPsw){
- //密码登录
- //验证码登录
- if(self.mobileTef.text.length == 0)
- {
- [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_phone")];
- return;
- }
-
- if(self.pswTef.text.length == 0){
- [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_password")];
- return;
- }
-
- [MBProgressHUD showActivityMessageInView:@""];
- WEAKSELF
- NSDictionary *mobileDict = @{@"code":self.chooseCountryBtn.titleLabel.text,
- @"num":self.mobileTef.text};
-
- NSString *pswStr = [self.pswTef.text md5String];
-
- NSDictionary *dict = @{@"mobile":mobileDict,
- @"pwd":pswStr,
- @"root":@(weakSelf.isRootMobile),
- @"virtual":@(weakSelf.isVirtual)};
- [weakSelf toLoginWithPswWithParams:dict];
- }
- else{
- //验证码登录
- if(self.mobileTef.text.length == 0)
- {
- [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_phone")];
- return;
- }
-
- if(self.smsTef.text.length == 0){
- [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_verify_code")];
- return;
- }
-
- [MBProgressHUD showActivityMessageInView:@""];
- WEAKSELF
- NSDictionary *mobileDict = @{@"code":self.chooseCountryBtn.titleLabel.text,
- @"num":self.mobileTef.text};
-
- NSDictionary *dict = @{@"mobile":mobileDict,
- @"code":self.smsTef.text,
- @"root":@(weakSelf.isRootMobile),
- @"virtual":@(weakSelf.isVirtual)};
-
- [weakSelf toLoginWithMobileWithParams:dict];
- }
-
- }
- - (void)toLoginWithMobileWithParams:(NSDictionary *)dict {
- WEAKSELF
- [kHttpManager logineWithMobileWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
-
- [MBProgressHUD hideHUD];
-
- if(kCode_Success){
- [weakSelf toNextVCWithData:data];
- }
- else{
- NSInteger code = [data[@"code"] integerValue];
- if(code == 90001){
- [MOTools dismissKeyboard];
- //腾讯验证码
- [weakSelf toShowTentcentCaptchaWebViewAndBlock:^(NSDictionary *result) {
- if (!result) {
- return;
- }
- kMainThreadBlock((^{
- NSMutableDictionary *newDict = [dict mutableCopy];
- NSString *appidStr = [MODataManager objectOrNilForKey:@"appid" fromDictionary:result];
- NSString *randStr = [MODataManager objectOrNilForKey:@"randstr" fromDictionary:result];
- NSString *ticketStr = [MODataManager objectOrNilForKey:@"ticket" fromDictionary:result];
- NSDictionary *verify = @{@"appid":appidStr,@"ticket":ticketStr,@"randStr":randStr};
- [newDict setObject:verify forKey:@"verify"];
- [weakSelf toLoginWithMobileWithParams:newDict];
- }))
- }];
- }
- else{
- NSString *errorString = [MODataManager objectOrNilForKey:@"msg" fromDictionary:data];
- [MBProgressHUD showTipMessageInView:errorString];
- }
- }
- }];
- }
- - (void)toLoginWithPswWithParams:(NSDictionary *)dict {
- WEAKSELF
- [kHttpManager loginWithPwdWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- [MBProgressHUD hideHUD];
-
- if(kCode_Success){
-
- [weakSelf toNextVCWithData:data];
- }
- else{
- NSInteger code = [data[@"code"] integerValue];
- if(code == 90001){
- [MOTools dismissKeyboard];
- //腾讯验证码
- [weakSelf toShowTentcentCaptchaWebViewAndBlock:^(NSDictionary *result) {
- if (!result) {
- return;
- }
- kMainThreadBlock((^{
- NSMutableDictionary *newDict = [dict mutableCopy];
- NSString *appidStr = [MODataManager objectOrNilForKey:@"appid" fromDictionary:result];
- NSString *randStr = [MODataManager objectOrNilForKey:@"randstr" fromDictionary:result];
- NSString *ticketStr = [MODataManager objectOrNilForKey:@"ticket" fromDictionary:result];
- NSDictionary *verify = @{@"appid":appidStr,@"ticket":ticketStr,@"randStr":randStr};
- [newDict setObject:verify forKey:@"verify"];
- [weakSelf toLoginWithPswWithParams:newDict];
- }))
- }];
- }
- else{
- NSString *errorString = [MODataManager objectOrNilForKey:@"msg" fromDictionary:data];
- [MBProgressHUD showTipMessageInView:errorString];
- }
- }
- }];
- }
- - (void)toNextVCWithData:(id)data{
- [MODataManager saveUserInfo:data];
-
- BOOL isRegister = [[MODataManager objectOrNilForKey:@"register" fromDictionary:data[@"data"]] boolValue];
- if(isRegister){
- //注册
- // ADJEvent *event = [ADJEvent eventWithEventToken:@"27ymyz"];
- ADJEvent *event = [[ADJEvent alloc] initWithEventToken:@"27ymyz"];
-
- NSString *userId = GetUserId;
- if(userId.length != 0){
- [event addCallbackParameter:@"userId" value:userId];
- }
-
- [Adjust trackEvent:event];
-
- MOFirstInfoSetVC *vc = [[MOFirstInfoSetVC alloc] init];
- [self.navigationController pushViewController:vc animated:YES];
- }
- else{
- MOMainTabController *mainTabbar = [MOMainTabController sharedSingleton];
- [mainTabbar toResetSetupTabbar];
- [UIApplication sharedApplication].keyWindow.rootViewController = mainTabbar;
- [mainTabbar ChangeNeedShowAlert];
- }
- }
- //切换登录模式
- - (IBAction)changeLoginType:(id)sender {
- self.isPsw = !self.isPsw;
- }
- - (MOCountDownButton *)smsBtn
- {
- if (!_smsBtn)
- {
- _smsBtn = [[MOCountDownButton alloc] init];
- _smsBtn.accessibilityIdentifier = @"smsBtn";
- _smsBtn.backgroundColor = kBaseBtnBgColor;
- [_smsBtn setTitle:[NSString stringWithFormat:@"%@",NSLocalString(@"mimo_verify_code_send")] forState:UIControlStateNormal];
- [_smsBtn setTitleColor:UIColorFromHex(0xFFFFFF) forState:UIControlStateNormal];
- _smsBtn.titleLabel.font = [MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr];;
- _smsBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
- _smsBtn.layer.cornerRadius = 35.0 / 2.0;
- _smsBtn.layer.masksToBounds = YES;
-
- // NSArray *colorArr = @[[MOTools colorWithHexString:@"#FF62EE" alpha:1.0],[MOTools colorWithHexString:@"#9923FF" alpha:1.0]];
- // UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, 80.0, 35.0) Colors:colorArr GradientType:0];
- // [_smsBtn setBackgroundImage:image forState:UIControlStateNormal];
-
- UIImage *grayImg = [MOTools createImageWithColor:[MOTools colorWithHexString:@"#ABABAB" alpha:1.0]];
- [_smsBtn setBackgroundImage:grayImg forState:UIControlStateDisabled];
-
- WEAKSELF
-
- //use case 8
- [_smsBtn countDownChanging:^NSString *(MOCountDownButton *countDownButton,NSUInteger second)
- {
- NSString *title = [NSString stringWithFormat:@"%@(%lus)",NSLocalString(@"mimo_login_resend"),(unsigned long)second];
- return title;
- }];
-
- [_smsBtn countDownFinished:^NSString *(MOCountDownButton *countDownButton, NSUInteger second)
- {
- countDownButton.enabled = YES;
- [countDownButton setTitleColor:UIColorFromHex(0xFFFFFF) forState:UIControlStateNormal];
- return NSLocalString(@"mimo_verify_code_send");
- }];
-
- [_smsBtn countDownButtonHandler:^(MOCountDownButton*sender, NSInteger tag)
- {
-
- if(weakSelf.mobileTef.text.length == 0)
- {
- [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_phone")];
- return;
- }
-
- [weakSelf sendSmsClickAndBlock:^(BOOL isSuccess) {
- if(isSuccess){
- sender.enabled = NO;
- [sender startCountDownWithSecond:60];
- }
- }];
- }];
- }
- return _smsBtn;
- }
- - (void)toShowTentcentCaptchaWebViewAndBlock:(void (^)(NSDictionary *dict))block{
-
- [self.view addSubview:self.webBgView];
- [self.webBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.view);
- }];
-
- [self.webBgView addSubview:self.webView];
- [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(self.webBgView);
- make.width.equalTo(@360);
- make.height.equalTo(@360);
- }];
- self.webBgView.hidden = NO;
-
- WEAKSELF
- TencentCaptchaOptions *options = [[TencentCaptchaOptions alloc] init];
- options.loadingEnabled = TencentCaptchaOptionsSwitchOff;
- options.type = @"popup";
- options.optionsCallback = ^(NSString * _Nonnull functionName, NSDictionary<NSString *,id> * _Nonnull data) {};
- NSString *currentLanguage = [NSBundle currentLanguage];
- if ([currentLanguage containsString:@"zh"]){
- currentLanguage = @"zh-cn";
- }
-
- options.userLanguage = currentLanguage;
- [options setExtractParameter:@(YES) forName:@"enableAutoCheck"];
- [[TencentCaptcha sharedService] requestCaptchaWithWebView:self.webView options:options withCompletionHandler:^(NSError * _Nullable error, NSDictionary * _Nullable result) {
- if(error == nil) {
- //成功
- MOLogV(@"验证成功");
- weakSelf.webBgView.hidden = YES;
- block(result);
- }
- else{
- block(nil);
- }
- }];
- }
- - (WKWebView *)webView {
- if (!_webView) {
- WKUserContentController *contentController = [[WKUserContentController alloc] init];
-
- WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
- config.userContentController = contentController;
-
- _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 360, 360) configuration:config];
- _webView.navigationDelegate = self;
- _webView.backgroundColor = [UIColor clearColor];
- _webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- }
- return _webView;
- }
- - (UIView *)webBgView{
- if(!_webBgView){
- _webBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, (SCREENHEIGHT - NAV_BAR_HEIGHT))];
- _webBgView.backgroundColor = [UIColor clearColor];
- }
- return _webBgView;
- }
- - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message{
- MOLogV(@"Received message: %@", message.body);
- }
- // 网页加载完成回调
- - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
- // JS 获取页面高度
- [webView evaluateJavaScript:@"document.body.scrollHeight" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
- if (!error && result) {
- CGFloat height = [result doubleValue];
- MOLogV(@"页面内容高度: %f", height);
- // 你可以根据这个高度调整 webView 的高度或外部容器视图
- // CGRect frame = webView.frame;
- // frame.size.height = height;
- // webView.frame = frame;
- }
- }];
- }
- @end
|