CNLiveInfoShowViewController.swift 5 KB
//
//  CNLiveInfoShowViewController.swift
//  metaCode
//
//  Created by open on 2023/6/8.
//

import Foundation
import WebKit

enum ListShowInfoType {
    case service
    case privacy
    case yinsi
}

class CNLiveInfoShowViewController: CNLiveBaseViewController, WKNavigationDelegate, WKUIDelegate {
    
    var _is_login:Bool!
    var _show_type:ListShowInfoType!
    init(show_type:ListShowInfoType,is_login:Bool) {
       super.init(nibName:nil, bundle:nil)
        _show_type = show_type
        _is_login = is_login
    }
    
    override func viewWillAppear(_ animated: Bool) {
        if _is_login {
            if (self.presentingViewController != nil) {
                //先设置一个默认返回按钮
                let left_btn = UIButton.backItem(imageName: "mine_header_icon_close", target: self, action: #selector(changeCancelAction))
                left_btn.backgroundColor = .white
                let leftBtn_array : Array<UIButton> = [left_btn]
                leftNavBtns = leftBtn_array
            }
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var webView: WKWebView = {
        let config = WKWebViewConfiguration()
        let webView = WKWebView.init(frame: .zero, configuration: config)
        webView.backgroundColor = .white
        webView.allowsBackForwardNavigationGestures = true
        webView.navigationDelegate = self
        webView.uiDelegate = self
        return webView
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBarHidden = false
        var attrString =  ""
        switch _show_type {
            case .service:
                titleName = "APP用户服务协议"
                attrString = "https://wjjh5.cnlive.com/yuanmaYhxy.html"
            case .privacy:
                titleName = "个人信息保护政策"
                attrString = "https://wjjh5.cnlive.com/yuanmaYszc.html"
            case .yinsi:
                titleName = "隐私协议"
                attrString = "https://wjjh5.cnlive.com/yuanmaYszc.html"
            case .none:
                break
            }
        
        view.addSubview(webView)
        webView.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(KNavigationHeight)
            make.left.right.bottom.equalToSuperview()
        }
        
        webView.load(URLRequest(url: URL(string: attrString)!, cachePolicy: .returnCacheDataElseLoad))

    }

    
    @objc func changeCancelAction() {
        if (self.presentingViewController != nil) {
            self.dismiss(animated: true)
        }else{
            self.navigationController!.popViewController(animated: true)
        }
    }
//    override func viewDidLoad() {
//        super.viewDidLoad()
//        var attrString =  ""
//        switch _show_type {
//        case .service:
//            titleName = "APP用户服务协议"
//            attrString = "欢迎您使用元码,我们非常重视您的个人信息保护,并采取了有效措施保障您的信息安全,请您充分了解: \n为保障APP账号安全,元码APP需向您申请获取电话状态权限。 \n请您务必阅读APP《个人信息保护政策》,以充分了解我们如何处理您的个人信息。"
//        case .privacy:
//            titleName = "个人信息保护政策"
//            attrString = "欢迎您使用元码,我们非常重视您的个人信息保护,并采取了有效措施保障您的信息安全,请您充分了解: \n为保障APP账号安全,元码APP需向您申请获取电话状态权限 \n请您务必阅读APP《个人信息保护政策》,以充分了解我们如何处理您的个人信息。"
//        case .none:
//            break
//        }
//
//        let paraph = NSMutableParagraphStyle()
//        paraph.lineSpacing = 10
//        let attributes = [NSAttributedString.Key.font:Font_16_Fit,
//                          NSAttributedString.Key.paragraphStyle: paraph]
//        let h = attrString.boundingRect(with: CGSize(width: KSreenWidth - 40, height: CGFloat(MAXFLOAT)), options: .usesLineFragmentOrigin, attributes: attributes, context: nil).size.height + 40
//        let textView = UITextView.init()
//        textView.attributedText = NSAttributedString(string: attrString, attributes: attributes)
//        textView.textColor = HexColor("#666666")
//        textView.layer.cornerRadius = 10
//        textView.layer.masksToBounds = true
//        textView.textAlignment  = .left
//        textView.contentMode = .scaleAspectFill
//        textView.contentInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
//        textView.sizeToFit()
//        view.addSubview(textView)
//        textView.snp.makeConstraints { make in
//            make.centerX.equalToSuperview()
//            make.top.equalToSuperview().offset(get_system_nav_height() + 10)
//            make.left.equalToSuperview().offset(10)
//            make.right.equalToSuperview().offset(-10)
//            make.height.equalTo(h)
//        }
//    }
    
}