#import "CBFeedbackController.h"
#import "WebViewJavascriptBridge.h"
#import <WebKit/WebKit.h>
@interface CBFeedbackController ()<UIWebViewDelegate>
@property (nonatomic, strong) WKWebView *htmlWebView;
@property (nonatomic, strong) WebViewJavascriptBridge *bridge;
@property (nonatomic, strong) UIProgressView *progressView;
@end
@implementation CBFeedbackController
- (void)viewDidLoad {
[super viewDidLoad];
[self setNavigationBarWhiteColor];
}
- (void)createUI {
self.title = @"意见反馈";
[self.view addSubview:self.htmlWebView];
[self.htmlWebView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
}
- (void)updateView {
kWeakSelf(self)
[self.htmlWebView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.bottom.equalTo(weakself.view);
}];
}
- (void)createViewModel {
kWeakSelf(self)
self.bridge = [WebViewJavascriptBridge bridgeForWebView:self.htmlWebView];
NSString *userNo = [CBDataAccessData getUserData].userNo;
NSString *token = [CBDataAccessData getUserData].token;
NSDictionary *dict = @{@"userNo":userNo, @"token":token, @"sysfrom": @"ios" };
[self.bridge callHandler:@"getUserMessage" data:dict responseCallback:^(id responseData) { }];
[self.bridge registerHandler:@"getStatus" handler:^(id data, WVJBResponseCallback responseCallback) {
NSString *message = [NSString stringWithFormat:@"%@",data];
[CBTipBoxView showTopTipSuccessfulContent:message];
[weakself.navigationController popViewControllerAnimated:YES];
}];
}
#pragma mark - KVC and KVO
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
if ([@"estimatedProgress" isEqualToString:keyPath]) {
[self.progressView setProgress:self.htmlWebView.estimatedProgress animated:NO];
}
if (self.progressView.progress == 0) {
self.progressView.hidden = NO;
} else if (self.progressView.progress == 1) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (self.progressView.progress ==1) {
self.progressView.progress = 0;
self.progressView.hidden = YES;
}
});
}
}
#pragma mark --- 实例化
- (WKWebView *)htmlWebView {
if (_htmlWebView == nil) {
_htmlWebView = [[WKWebView alloc] init];
NSURLRequest *requestUrl = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://baidu.com"]];
[_htmlWebView loadRequest:requestUrl];
}
return _htmlWebView;
}
-(UIProgressView *)progressView {
if (_progressView == nil) {
CGRect rect = CGRectZero;
rect.size.width = [[UIScreen mainScreen]bounds].size.width;
rect.size.height = 2;
_progressView = [[UIProgressView alloc]initWithFrame:rect];
_progressView.progressTintColor = [UIColor hexColor:@"#FFC400"];
[_progressView setProgressViewStyle:UIProgressViewStyleDefault];
[self.view addSubview:_progressView];
}
return _progressView;
}
- (void)dealloc {
[self.htmlWebView removeObserver:self forKeyPath:@"estimatedProgress"];
self.htmlWebView = nil;
[self.htmlWebView removeFromSuperview];
}
@end
WebViewJavascriptBridge JS和OC交互
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- WebViewJavascriptBridge 是一个封装处理好的第三方库.功能非常强大.下面就简单介绍一下如何使...
- 我要实现这样一个需求:按照本地的CSS文件展示一串网络获取的带HTML格式的只有body部分的文本,需要自己拼写完...
- 最近开发中做H5和OC混编开发,需要通过JS调用iPhone的相册,并把图片传给Web端,然后显示在Web端,具体...