// // RDSControlWebVC.m // Temperature // // Created by Kevin on 2023/12/6. #import "RDSControlWebVC.h" #import #import @interface RDSControlWebVC () @property (nonatomic, strong) WKWebView *webView; @property (nonatomic, strong) WebViewJavascriptBridge *bridge; @property (nonatomic, copy) NSString *requestURL; @end @implementation RDSControlWebVC - (instancetype)initWithRecordId:(NSString *)recordId code:(NSString *)code { self = [super init]; if (self) { self.requestURL = [NSString stringWithFormat:@"https://app.yongxulvjian.com/#/Room/%@/%@", recordId, code]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self configSubviews]; [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.requestURL]]]; } - (void)configSubviews { [self.view addSubview:self.webView]; [self.webView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(UIEdgeInsetsZero); }]; } - (void)jsBridge { RDS_WEAKSELF(weakSelf) self.bridge = [WebViewJavascriptBridge bridgeForWebView:_webView]; [self.bridge setWebViewDelegate:self]; // js 回调 [self.bridge registerHandler:@"closeWebView" handler:^(id data, WVJBResponseCallback responseCallback) { [weakSelf.navigationController popViewControllerAnimated:YES]; }]; } - (WKWebView *)webView { if (!_webView) { WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init]; config.userContentController = [[WKUserContentController alloc] init]; config.allowsInlineMediaPlayback = YES; _webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:config]; _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; // _webView.UIDelegate = self; // _webView.navigationDelegate = self; [self jsBridge]; } return _webView; } @end