123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691 |
- //
- // RQWebViewViewController.m
- // RQCommon
- //
- // Created by 张嵘 on 2018/11/27.
- // Copyright © 2018 张嵘. All rights reserved.
- //
- #import "RQWebViewViewController.h"
- #import "WebViewJavascriptBridge.h"
- #import "faceView.h"
- #import "UIView+ITTAdditions.h"
- #import "OliveappLivenessDetectionViewController.h"
- #import "OliveappCameraPreviewController.h"
- #import "OliveappDetectedFrame.h"
- #import <AVFoundation/AVFoundation.h>
- #import "OliveappIdcardCaptorViewController.h"
- #import "OliveappBase64Helper.h"
- #import "OliveappImageUtility.h"
- #import "YYTimer.h"
- @interface RQWebViewViewController () <OliveappLivenessResultDelegate,FaceDetectorsDelegate,UIScrollViewDelegate>
- /// webView
- @property (nonatomic, weak, readwrite) WKWebView *webView;
- /// 进度条
- @property (nonatomic, readwrite, strong) UIProgressView *progressView;
- /// 返回按钮
- @property (nonatomic, readwrite, strong) UIBarButtonItem *backItem;
- /// 关闭按钮 (点击关闭按钮 退出WebView)
- @property (nonatomic, readwrite, strong) UIBarButtonItem *closeItem;
- @property (nonatomic, strong, readwrite) WebViewJavascriptBridge *bridge;
- @property (nonatomic, readwrite, copy) WVJBResponseCallback imgCallBack;
- @property (nonatomic, readwrite, assign) BOOL isLoad;
- @property (nonatomic, readwrite, assign) BOOL currentIsInBottom;
- /// Timer
- @property (nonatomic, readwrite, strong) YYTimer *timer;
- /// Count
- @property (nonatomic, readwrite, assign) NSUInteger count;
- @end
- @implementation RQWebViewViewController
- - (void)dealloc {
- /// remove observer ,otherwise will crash
- [_webView stopLoading];
- _isLoad = NO;
- self.timer = nil;
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self.navigationController.navigationBar setHidden:_webType == WebTypeEDU];
-
- /// 清除缓存
- // NSSet *websiteDataTypes = [WKWebsiteDataStore allWebsiteDataTypes];
- // NSArray *types = @[WKWebsiteDataTypeMemoryCache,WKWebsiteDataTypeDiskCache];
- /*
- NSArray *type = @[WKWebsiteDataTypeDiskCache, // 磁盘缓存
- WKWebsiteDataTypeMemoryCache, // 内存缓存
- WKWebsiteDataTypeOfflineWebApplicationCache, // HTML 离线 Web 应用程序缓存。
- WKWebsiteDataTypeCookies, // Cookies
- WKWebsiteDataTypeSessionStorage, // HTML 会话存储
- WKWebsiteDataTypeLocalStorage, // HTML 本地存储
- WKWebsiteDataTypeWebSQLDatabases, // WebSQL 数据库
- WKWebsiteDataTypeIndexedDBDatabases, // IndexedDB 数据库
- ];
- */
-
- // NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
- // NSSet *websiteDataTypes = [NSSet setWithArray:types];
- // [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
- // }];
-
- NSString *encodedString = (NSString*) CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(CFStringRef)self.url,(CFStringRef)@"!$&'()*+,-./:;=?@_~%#[]",NULL, kCFStringEncodingUTF8));
- NSURL *httpUrl = [NSURL URLWithString:encodedString];
- if (!_isLoad) {
- /// 加载请求数据
- [self.view addSubview:self.progressView];
- NSURLRequest *request = [NSURLRequest requestWithURL:httpUrl];
- [self.webView loadRequest:request];
- }
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- [self.progressView removeFromSuperview];
- [self.navigationController.navigationBar setHidden:NO];
- }
- - (void)viewDidLoad {
- @weakify(self);
- [super viewDidLoad];
-
- self.navigationItem.leftBarButtonItem = self.backItem;
-
- ///RQ-MARK FIXED: 切记 lightempty_ios 是前端跟H5商量的结果,请勿修改。
- NSString *userAgent = @"";
-
- if (!(([[[UIDevice currentDevice] systemVersion] floatValue]) >= 9.0)) [[NSUserDefaults standardUserDefaults] registerDefaults:@{@"userAgent":userAgent}];
-
- /// 注册JS
- WKUserContentController *userContentController = [[WKUserContentController alloc] init];
- /// 这里可以注册JS的处理 涉及公司私有方法 这里笔者不作处理
-
- WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
- configuration.allowsInlineMediaPlayback = YES;
- if (@available(iOS 10.0, *)) {
- configuration.mediaTypesRequiringUserActionForPlayback = NO;
- }
- NSMutableString *jsString = [NSMutableString string];
- /// 自适应屏幕宽度
- [jsString appendString:@"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);"];
- /// 禁止长按
- [jsString appendString:@"document.documentElement.style.webkitTouchCallout='none';"];
- /// 禁止选择
- [jsString appendString:@"document.documentElement.style.webkitUserSelect='none';"];
- /// 关闭H5的缩放手势
- [jsString appendString:@"var script = document.createElement('meta');"
- "script.name = 'viewport';"
- "script.content=\"width=device-width, initial-scale=1.0,maximum-scale=1.0, minimum-scale=1.0, user-scalable=no\";"
- "document.getElementsByTagName('head')[0].appendChild(script);"];
- WKUserScript *userScript = [[WKUserScript alloc] initWithSource:jsString injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
- /// 添加屏幕js调用的方法
- [userContentController addUserScript:userScript];
- /// 赋值userContentController
- configuration.userContentController = userContentController;
- WKWebView *webView;
- switch (_webType) {
- case WebTypeEDU: {
- webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, RQ_APPLICATION_STATUS_BAR_HEIGHT, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - RQ_APPLICATION_STATUS_BAR_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT) configuration:configuration];
- break;
- }
- case WebTypeStuLearnBook: {
- self.count = self.countStr.integerValue;
- self.timer = [YYTimer timerWithTimeInterval:1 target:self selector:@selector(_timerValueChanged:) repeats:YES];
- webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - RQ_APPLICATION_TOP_BAR_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT) configuration:configuration];
- }
- break;
- case WebTypeStuProtocol: {
- webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - RQ_APPLICATION_TOP_BAR_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT) configuration:configuration];
- break;
- }
- default: {
- webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT) configuration:configuration];
- break;
- }
- }
-
- webView.navigationDelegate = self;
- webView.UIDelegate = self;
- webView.scrollView.delegate = self;
-
- if (@available(iOS 9.0, *)) {
- webView.customUserAgent = userAgent;
- } else {
- // Fallback on earlier versions
- }
- self.webView = webView;
- [self.view addSubview:webView];
-
- // 开启日志,方便调试
- [WebViewJavascriptBridge enableLogging];
- // 给哪个webview建立JS与OjbC的沟通桥梁
- _bridge = [WebViewJavascriptBridge bridgeForWebView:self.webView];
- [_bridge setWebViewDelegate:self];
- // OC端通过responseCallback回调JS端,JS就可以得到所需要的数据
- [self.bridge registerHandler:@"closeWindows" handler:^(id data, WVJBResponseCallback responseCallback) {
- if (responseCallback) {
- // 反馈给JS
- // responseCallback(@{@"userId": @"123456"});
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"退出" message:@"确定退出在线学习吗?" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- responseCallback(@"1");
- // 开启返回手势
- if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
- self.navigationController.interactivePopGestureRecognizer.enabled = YES;
- }
- [self.navigationController popViewControllerAnimated:YES];
- }];
- [alert addAction:saveAction];
- WKBackForwardListItem *item = self.webView.backForwardList.currentItem;
- NSLog(@"-----%@------",[item.URL.absoluteString componentsSeparatedByString:@"/"].lastObject);
- if ([[item.URL.absoluteString componentsSeparatedByString:@"/"].lastObject isEqualToString:@"plan"]) {
- UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- responseCallback(@"0");
- }];
- [alert addAction:cancleAction];
- }
-
- [self presentViewController:alert animated:YES completion:nil];
- }
- }];
- [self.bridge registerHandler:@"closeH5" handler:^(id data, WVJBResponseCallback responseCallback) {
- if (responseCallback) {
- // 反馈给JS
- // responseCallback(@{@"userId": @"123456"});
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"退出" message:@"确定退出在线学习吗?" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- responseCallback(@"1");
- // 开启返回手势
- if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
- self.navigationController.interactivePopGestureRecognizer.enabled = YES;
- }
- [self.navigationController popViewControllerAnimated:YES];
- }];
- [alert addAction:saveAction];
- WKBackForwardListItem *item = self.webView.backForwardList.currentItem;
- NSLog(@"-----%@------",[item.URL.absoluteString componentsSeparatedByString:@"/"].lastObject);
- if (![self.webView.URL.absoluteString containsString:@"http://lncx.anjia365.com"] || ([self.webView.URL.absoluteString containsString:@"http://lncx.anjia365.com"] && [[item.URL.absoluteString componentsSeparatedByString:@"/"].lastObject isEqualToString:@"plan"])) {
- UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- responseCallback(@"0");
- }];
- [alert addAction:cancleAction];
- }
-
- [self presentViewController:alert animated:YES completion:nil];
- }
- }];
- [_bridge registerHandler:@"photoClick" handler:^(id data, WVJBResponseCallback responseCallback) {
- if (responseCallback) {
- _imgCallBack = responseCallback;
- }
- // FaceStreamDetectorViewController *faceVC = [[FaceStreamDetectorViewController alloc]init];
- // faceVC.faceDelegate = self;
- // faceVC.modalPresentationStyle = UIModalPresentationFullScreen;
- // [self presentViewController:faceVC animated:YES completion:^{
- //
- // }];
- [self postuploadPhotoLog];
- self.hidesBottomBarWhenPushed = YES;
- NSArray *arr = [self.webView.URL.absoluteString componentsSeparatedByString:@"/"];
- NSString *myUrl = @"";
- if (arr.count > 3) {
- myUrl = arr[2];
- }
- if ([RQ_COMMON_MANAGER.oldFaceHistoryListListArr containsObject:myUrl]) {
- [self checkBodyInfo];
- } else {
- [[RACScheduler mainThreadScheduler] schedule:^{
- [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:RQ_COMMON_MANAGER.LN_NET_EDU_FACE_NUM completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
- @strongify(self);
- if (success) {
- if (self.imgCallBack) {
- [MBProgressHUD rq_showProgressHUD:@"验证中..."];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- NSString *backString = [NSString stringWithFormat:@"data:image/jpeg;base64,%@",dic[@"normalImg"]];
- self.imgCallBack(backString);
- [MBProgressHUD rq_hideHUD];
- });
- }
- }
- }];
- }];
- }
- }];
-
- /// oc调用js
- [webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id result, NSError *error) {
- NSLog(@"navigator.userAgent.result is ++++ %@", result);
- }];
-
- /// 监听数据
- [RACObserve(self.webView, title) subscribeNext:^(NSString *titleStr) {
- @strongify(self);
- NSLog(@"%@",titleStr);
- /// CoderMikeHe FIXED: 这里只设置导航栏的title 以免self.title 设置了tabBarItem.title
- switch (_webType) {
- case WebTypeStuProtocol: {
- self.navigationItem.title = @"学员报名合同";
- break;
- }
- case WebTypeStuLearnBook: {
- self.navigationItem.title = self.titleStr;
- break;
- }
- default: {
- self.navigationItem.title = self.webView.title;
- break;
- }
- }
- }];
-
- [RACObserve(self.webView, loading) subscribeNext:^(NSNumber *currentLoadingState) {
- BOOL isLoading = [currentLoadingState boolValue];
- if (isLoading) {
- [MBProgressHUD showLoadToView:[UIApplication sharedApplication].keyWindow];
- NSLog(@"--- webView is loading ---");
- }else {
- NSLog(@"--- webView isn't loading ---");
- [MBProgressHUD hideHUDForView:[UIApplication sharedApplication].keyWindow];
- }
- }];
- [RACObserve(self.webView, estimatedProgress) subscribeNext:^(NSNumber *estimatedProgressValue) {
- NSLog(@"%@",estimatedProgressValue);
- @strongify(self);
- [self.progressView setAlpha:1.0f];
- [self.progressView setProgress:self.webView.estimatedProgress animated:YES];
- if(self.webView.estimatedProgress >= 1.0f) {
- [UIView animateWithDuration:0.3 delay:0.3 options:UIViewAnimationOptionCurveEaseOut animations:^{
- [self.progressView setAlpha:0.0f];
- } completion:^(BOOL finished) {
- [self.progressView setProgress:0.0f animated:NO];
- _isLoad = YES;
- }];
- }
- }];
-
-
- //监听UIWindow隐藏
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endFullScreen) name:UIWindowDidBecomeHiddenNotification object:nil];
- /// 添加刷新控件
- // if(self.viewModel.shouldPullDownToRefresh){
- // [self.webView.scrollView rq_addHeaderRefresh:^(MJRefreshNormalHeader *header) {
- // @strongify(self);
- // [self.webView reload];
- // }];
- // [self.webView.scrollView.mj_header beginRefreshing];
- // }
- self.webView.scrollView.contentInset = self.contentInset;
-
-
-
- /// RQ-MARK: 适配 iPhone X + iOS 11,去掉安全区域
- if (@available(iOS 11.0, *)) {
- RQAdjustsScrollViewInsets_Never(webView.scrollView);
- }
-
- }
- - (void)endFullScreen {
- [self prefersStatusBarHidden];
- }
- - (void)sendFaceImage:(UIImage *)faceImage {
- NSLog(@"-----------------------%@------%@",self.webView.URL.absoluteString,[self.webView.URL.absoluteString containsString:@"http://lncx.anjia365.com"]? @"YES" : @"NO");
- UIImage *normalImage = [UIImage fixOrientation:faceImage];
- /// 通安
- if ([self.webView.URL.absoluteString containsString:@"http://lncx.anjia365.com"]) {
- normalImage = [UIImage imageWithCGImage:normalImage.CGImage
- scale:normalImage.scale
- orientation:UIImageOrientationDown];
- }
- NSData *imgData = UIImageJPEGRepresentation(normalImage, .2f);
- NSString *backString = [NSString stringWithFormat:@"data:image/jpeg;base64,%@",[OliveappBase64Helper encode:imgData]];
- @weakify(self);
- if (self.imgCallBack) {
- @strongify(self);
- [MBProgressHUD showLoadToView:self.view];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- self.imgCallBack(backString);
- [MBProgressHUD hideHUDForView:self.view];
- });
- }
- }
- - (void)sendFaceImageError {
-
- }
- //base64encode then urlencode (采用这个方法,一步到位)
- - (NSString *)base64AndUrlencodeStringFromData: (NSData *)data {
-
- NSString *base64String = [data base64EncodedStringWithOptions:0];
-
- NSString *encodedString = (NSString *)
- CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
- (CFStringRef)base64String,
- NULL,
- (CFStringRef)@"!*'();:@&=+$,/?%#[]",
- kCFStringEncodingUTF8));
-
- return encodedString;
- }
- // 活体检测
- - (void)checkBodyInfo{
- UIStoryboard * board = [UIStoryboard storyboardWithName:@"LivenessDetection" bundle:nil];
- OliveappLivenessDetectionViewController * livenessDetectionViewController;
- livenessDetectionViewController = (OliveappLivenessDetectionViewController *)[ board instantiateViewControllerWithIdentifier:@"LivenessDetectionStoryboard"];
- livenessDetectionViewController.modalPresentationStyle = 0;
- livenessDetectionViewController.faceDelegate = self;
- OliveappSessionManagerConfig* config = [OliveappSessionManagerConfig new];
- // config.timeoutMs = 100000;
- [config usePredefinedConfig: 4]; // 这里配置检测步骤
- livenessDetectionViewController.cusConfig = config;
- NSError *error;
- BOOL isSuccess = [livenessDetectionViewController setConfigLivenessDetection:self withError: &error];
- if (isSuccess){
- // [self.navigationController pushViewController:livenessDetectionViewController animated:YES];
- [self presentViewController:livenessDetectionViewController animated:YES completion:^{
-
- }];
- }
- }
- - (void)onLivenessSuccess:(OliveappDetectedFrame *)detectedFrame{
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self dismissViewControllerAnimated:YES completion:nil];
- // if (self.imgCallBack) {
- // NSMutableData *datas = detectedFrame.verificationData.mutableCopy;
- // NSData *adata = [[NSData alloc] initWithBytes:detectedFrame.verificationData.bytes length:detectedFrame.verificationData.length];
- // NSString * str =[self base64AndUrlencodeStringFromData:datas];
- //
- // UIImage *iamge0 = [UIImage imageWithData:[datas subdataWithRange:NSMakeRange(8, datas.length - 8)]];
- //
- //
- // UIImage *image = [UIImage imageWithData:datas];
- // UIImage *image1 = [UIImage imageWithData:adata];
- // UIImage *image2 = [OliveappImageUtility convertBitmapRGBA8ToUIImage:(unsigned char *)detectedFrame.verificationData.bytes withWidth:100 withHeight:100];
- //
- // NSString *backString = [OliveappBase64Helper encode:datas];
- // NSString *backString1 = [NSString stringWithFormat:@"data:image/jpeg;base64,%@",str];
- // self.imgCallBack(backString1);
- // }
- // [self.navigationController popViewControllerAnimated:YES];
- });
- }
- - (void)onLivenessFail:(int)sessionState withDetectedFrame:(OliveappDetectedFrame *)detectedFrame{
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self dismissViewControllerAnimated:YES completion:nil];
- UIAlertController *actionsheet = [UIAlertController alertControllerWithTitle:@"提示" message:@"活体检测失败,是否重新进行活体检测" preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"是" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [self checkBodyInfo];
- }];
-
- UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"否" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- }];
- [actionsheet addAction:action1];
- [actionsheet addAction:action2];
-
- [self presentViewController:actionsheet animated:YES completion:nil];
- });
- }
- - (void)onLivenessCancel{
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self dismissViewControllerAnimated:YES completion:nil];
- });
- }
- - (void)scrollViewDidScroll:(UIScrollView*)scrollView {
- CGFloat height = scrollView.frame.size.height;
- CGFloat contentOffsetY = scrollView.contentOffset.y;
- CGFloat bottomOffset = scrollView.contentSize.height - contentOffsetY;
- if (bottomOffset <= height) {
- //在最底部
- self.currentIsInBottom = YES;
- } else {
-
- }
- }
- #pragma mark - 事件处理
- - (void)_backItemDidClicked{ /// 返回按钮事件处理
- /// 可以返回到上一个网页,就返回到上一个网页
- if (self.webView.canGoBack) {
- [self.webView goBack];
- } else {/// 不能返回上一个网页,就返回到上一个界面
- NSArray *viewcontrollers = self.navigationController.viewControllers;
- if(viewcontrollers.count>1) {
- if([viewcontrollers objectAtIndex:viewcontrollers.count-1] == self) {
- //push方式
-
- if (self.webType == WebTypeStuLearnBook) {
- if (self.currentIsInBottom) {
- if (self.count == 0) {
- NSString *key1 = [NSString stringWithFormat:@"getAppAnnouncementShowOne%@",RQ_APPDELEGATE.announcementId];
- NSString *key2 = [NSString stringWithFormat:@"getAppAnnouncementShowTwo%@",RQ_APPDELEGATE.announcementId];
- if ([[RQPreferenceSettingHelper objectForKey:key1] boolValue]) {
- [RQPreferenceSettingHelper setObject:@(YES) forKey:key2];
- } else {
- [RQPreferenceSettingHelper setObject:@(YES) forKey:key1];
- }
- [self.navigationController popViewControllerAnimated:YES];
- } else {
- NSString *message = [NSString stringWithFormat:@"至少观看%@秒",self.countStr];
- [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:message confirmTitle:@"确定"];
- }
- } else {
- [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"请滑动页面内容到底部!" confirmTitle:@"确定"];
- }
- } else {
- [self.navigationController popViewControllerAnimated:YES];
- }
-
- }
- } else {
- //present方式
- [self.navigationController dismissViewControllerAnimated:YES completion:NULL];
- }
- }
- }
- - (void)_closeItemDidClicked{
- /// 判断 是Push还是Present进来的
- [self.navigationController dismissViewControllerAnimated:YES completion:NULL];
- }
- - (UIEdgeInsets)contentInset {
- return UIEdgeInsetsMake(0, 0, 0, 0);
- }
- - (void)_timerValueChanged:(YYTimer *)timer{
- self.count--;
- if (self.count == 0) {
- [timer invalidate];
- self.timer = nil;
- return;
- }
- }
- #pragma mark - WKScriptMessageHandler
- - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message{
- /// js call OC function
-
- }
- #pragma mark - WKNavigationDelegate
- /// 内容开始返回时调用
- - (void)webView:(WKWebView *)webView didCommitNavigation:(null_unspecified WKNavigation *)navigation {
- UIBarButtonItem *backItem = self.navigationItem.leftBarButtonItems.firstObject;
- if (backItem) {
- if ([self.webView canGoBack]) {
- [self.navigationItem setLeftBarButtonItems:@[backItem, self.closeItem]];
- } else {
- [self.navigationItem setLeftBarButtonItems:@[backItem]];
- }
- }
- }
- - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
- if (navigationType==UIWebViewNavigationTypeBackForward) {
- self.webView.canGoBack?[self.webView goBack]:[self.navigationController popViewControllerAnimated:YES];
- }
- return YES;
- }
- // 导航完成时,会回调(也就是页面载入完成了)
- - (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation {
- // if (self.viewModel.shouldPullDownToRefresh) [webView.scrollView.mj_header endRefreshing];
- // 禁用返回手势
- if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
- self.navigationController.interactivePopGestureRecognizer.enabled = NO;
- }
-
- if (self.webType == WebTypeStuLearnBook) {
- self.navigationController.interactivePopGestureRecognizer.enabled = NO;
- }
- }
- // 导航失败时会回调
- - (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
- // if (self.viewModel.shouldPullDownToRefresh) [webView.scrollView.mj_header endRefreshing];
- // 开启返回手势
- if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
- self.navigationController.interactivePopGestureRecognizer.enabled = YES;
- }
- }
- // 在发送请求之前,决定是否跳转
- - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
- NSLog(@"navigationAction.request.URL: %@", navigationAction.request.URL);
- decisionHandler(WKNavigationActionPolicyAllow);
- }
- - (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
- decisionHandler(WKNavigationResponsePolicyAllow);
- }
- - (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *__nullable credential))completionHandler {
- NSURLCredential *cred = [[NSURLCredential alloc] initWithTrust:challenge.protectionSpace.serverTrust];
- completionHandler(NSURLSessionAuthChallengeUseCredential, cred);
- }
- #pragma mark - WKUIDelegate
- - (nullable WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures {
- /// CoderMike Fixed : 解决点击网页的链接 不跳转的Bug。
- WKFrameInfo *frameInfo = navigationAction.targetFrame;
- if (![frameInfo isMainFrame]) {
- [webView loadRequest:navigationAction.request];
- }
- return nil;
- }
- #pragma mark runJavaScript
- - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler {
- // [NSObject rq_showAlertViewWithTitle:nil message:message confirmTitle:@"我知道了"];
- completionHandler();
- }
- - (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler {
- completionHandler(YES);
- }
- - (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(nullable NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * __nullable result))completionHandler {
- completionHandler(defaultText);
- }
- #pragma mark - Getter & Setter
- - (UIProgressView *)progressView {
- if (!_progressView) {
- CGFloat progressViewW = ([[UIScreen mainScreen] bounds].size.width);
- CGFloat progressViewH = 3;
- CGFloat progressViewX = 0;
- CGFloat progressViewY = 0;
- UIProgressView *progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(progressViewX, progressViewY, progressViewW, progressViewH)];
- progressView.progressTintColor = [UIColor colorWithRed:(253 / 255.0) green:(103 / 255.0) blue:(27 / 255.0) alpha:1];
- progressView.trackTintColor = [UIColor clearColor];
- [self.view addSubview:progressView];
- self.progressView = progressView;
- }
- return _progressView;
- }
- - (UIBarButtonItem *)backItem
- {
- if (_backItem == nil) {
- _backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"question_pre_checked_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(_backItemDidClicked)];
- [_backItem setTintColor:defGreen];
- self.navigationController.navigationBar.translucent = NO;
- [self.navigationItem setLeftBarButtonItem:_backItem];
- }
- return _backItem;
- }
- - (UIBarButtonItem *)closeItem {
- if (!_closeItem) {
- // _closeItem = [UIBarButtonItem rq_systemItemWithTitle:@"关闭" titleColor:nil imageName:nil target:self selector:@selector(_closeItemDidClicked) textType:YES];
- }
- return _closeItem;
- }
- - (void)postuploadPhotoLog {
- // if (![Util connectedToNetWork]) {
- // showMsgUnconnect();
- // return;
- // }
-
- NSMutableArray *aArray=[NSMutableArray array];
- [aArray addPro:@"idcard" Value:[NSString stringWithFormat:@"%@",defUser.userDict[@"loginCode"]]];
- [aArray addPro:@"outid" Value:[NSString stringWithFormat:@"%@",defUser.userDict[@"outId"]]];
-
- NSString* method = @"uploadPhotoLog";
- [jiaPeiManager requestAnythingWithURL:method array:aArray data:nil completion:^(NSDictionary *root) {
- // if (!root) {
- // ShowMsgFailed();
- // return ;
- // }
- //
- // if ([root[@"code"] isEqualToString:@"0"]) {
- //
- // } else {
- //// ShowMsg(root[@"msg"]);
- // return ;
- // }
- }];
- }
- @end
|