// // YXAlertView.m // Temperature // // Created by TC on 2025/4/25. // #import "YXAlertView.h" #import @interface YXAlertView() @property (weak, nonatomic) UIView *contentView; @property (nonatomic, strong) WKWebView *webView; @property (nonatomic, strong) UILabel *textlabel; @end @implementation YXAlertView - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { // self.requestURL = @"https://app.yongxulvjian.com/#/PrivacyPolicy"; [self createCoverView]; [self createContentView]; } return self; } -(void)createCoverView { UIView *coverView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; coverView.backgroundColor = [UIColor blackColor]; coverView.alpha = 0.3; [self addSubview:coverView]; } -(void)createContentView { UIView *contentView = [[UIView alloc]init]; contentView.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"]; [self addSubview:contentView]; self.contentView = contentView; [contentView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(@0); make.centerY.equalTo(@0); make.width.equalTo(@(SCREEN_WIDTH - 80)); make.height.equalTo(@(350)); }]; contentView.layer.cornerRadius = 10; UILabel *titleLabel = [[UILabel alloc]init]; titleLabel.text = @"个人信息隐私保护政策"; titleLabel.textColor = [UIColor colorWithHexString:@"#1F1F1F"]; titleLabel.font = [UIFont boldSystemFontOfSize:18]; titleLabel.textAlignment = NSTextAlignmentCenter; [contentView addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(@30); make.centerX.equalTo(contentView.mas_centerX); make.height.equalTo(@30); make.width.equalTo(@260); }]; WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init]; config.userContentController = [[WKUserContentController alloc] init]; config.allowsInlineMediaPlayback = YES; WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:config]; webView.navigationDelegate = self; webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; [contentView addSubview:webView]; [webView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(titleLabel.mas_bottom); make.left.equalTo(@7); make.right.equalTo(@-7); make.bottom.equalTo(@-80); }]; self.webView = webView; // [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.requestURL]]]; NSString* htmlPath = [[NSBundle mainBundle] pathForResource:@"YXAlertText" ofType:@"html"]; NSString* appHtml = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil]; NSURL *baseURL = [NSURL fileURLWithPath:htmlPath]; [self.webView loadHTMLString:appHtml baseURL:baseURL]; // UILabel *textLabel = [[UILabel alloc]init]; // textLabel.text = @"欢迎使用永续绿建五恒 APP,我们非常重视您的隐私保护和个人信息保护,使用本软件的过程中我们会严格按照法律规定收集存储和使用您的个人信息,未经您的同意我们不会向第三方提供您的任何信息,您可以阅读《用户协议》和《隐私政策》全文了解详细信息。如您同意,请点击“同意”开始接受我们的服务。"; // textLabel.textColor = [UIColor colorWithHexString:@"#1F1F1F"]; // textLabel.font = [UIFont systemFontOfSize:15]; // textLabel.textAlignment = NSTextAlignmentJustified; // textLabel.numberOfLines = 0; // [contentView addSubview:textLabel]; // [textLabel mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(titleLabel.mas_bottom); // make.left.equalTo(@30); // make.right.equalTo(@-30); // make.bottom.equalTo(@-80); // }]; UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [rightBtn setTitle:@"不同意" forState:UIControlStateNormal]; [rightBtn addTarget:self action:@selector(rightBtnAction:) forControlEvents:UIControlEventTouchUpInside]; [rightBtn setTitleColor:[UIColor colorWithHexString:@"#585D66"] forState:UIControlStateNormal]; rightBtn.titleLabel.font = [UIFont systemFontOfSize:16]; rightBtn.backgroundColor = [UIColor colorWithHexString:@"#F2F5FA"]; [contentView addSubview:rightBtn]; [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(webView.mas_bottom).offset(20); make.left.equalTo(@40); make.height.equalTo(@40); make.width.equalTo(@100); }]; rightBtn.layer.cornerRadius = 20; UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [sureBtn setTitle:@"同意" forState:UIControlStateNormal]; [sureBtn addTarget:self action:@selector(sureBtnAction:) forControlEvents:UIControlEventTouchUpInside]; [sureBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal]; sureBtn.titleLabel.font = [UIFont systemFontOfSize:16]; sureBtn.backgroundColor = [UIColor colorWithHexString:@"#267AFF"]; [contentView addSubview:sureBtn]; [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(webView.mas_bottom).offset(20); make.right.equalTo(@-40); make.height.equalTo(@40); make.width.equalTo(@100); }]; sureBtn.layer.cornerRadius = 20; } -(void)rightBtnAction:(UIButton *)btn { if (self.cancleBtnClick) { self.cancleBtnClick(self); } exit(0); } -(void)sureBtnAction:(UIButton *)btn { if (self.sureBtnClick) { self.sureBtnClick(self); } } #pragma mark - WKNavigationDelegate - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { NSURL *url = navigationAction.request.URL; NSString *urlString = [url absoluteString]; if ([urlString hasPrefix:@"https://app.yongxulvjian.com"]) { if (self.contentClick) { self.contentClick(self, urlString); } decisionHandler(WKNavigationActionPolicyCancel); }else{ decisionHandler(WKNavigationActionPolicyAllow); } // // 获取请求的 URL // NSURL *url = navigationAction.request.URL; // NSString *urlString = [url absoluteString]; // // // 检查 URL 是否需要被拦截或修改 // if ([urlString hasPrefix:@"http://example.com/somepath"]) { // // 处理内部跳转或修改 URL // NSURL *newURL = [NSURL URLWithString:@"https://newexample.com"]; // 示例:修改 URL // NSURLRequest *newRequest = [NSURLRequest requestWithURL:newURL]; // [webView loadRequest:newRequest]; // decisionHandler(WKNavigationActionPolicyCancel); // 取消原始请求,加载新请求 // } else { // // 允许其他 URL 正常加载 // decisionHandler(WKNavigationActionPolicyAllow); // } } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end