//
|
// PPTVController.m
|
// BuWanVideo2.0
|
//
|
// Created by Aeline on 2021/2/27.
|
// Copyright © 2021 com.yeshi.buwansheque.ios. All rights reserved.
|
//
|
|
#import "PPTVController.h"
|
#import "PPTVNavView.h"
|
#import "PPTVPppView.h"
|
#import "PPTVBottomVIpVIew.h"
|
#import <WebKit/WebKit.h>
|
|
#import "dsbridge.h"
|
#import "JSAPI.h"
|
|
@interface PPTVController () <WKNavigationDelegate, WKUIDelegate, PPTVDelegate>
|
|
@property (nonatomic, nullable, strong) DWKWebView *webView;
|
@property (nonatomic, nullable, strong) PPTVNavView *viewPPTVNav;
|
@property (nonatomic, nullable, strong) PPTVPppView *viewPPTVPop;
|
@property (nonatomic, nullable, strong) PPTVBottomVIpVIew *viewPPTVVip;
|
|
@property (nonatomic, nullable, strong) JSAPI *jsAPI;
|
|
@property (nonatomic, nullable, copy) NSString *name;
|
@property (nonatomic, nullable, copy) NSString *content;
|
@end
|
|
@implementation PPTVController
|
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
[self loadViewConfig];
|
}
|
|
- (void)dealloc
|
{
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
}
|
|
- (void)viewWillAppear:(BOOL)animated {
|
[super viewWillAppear:animated];
|
[self.navigationController setNavigationBarHidden:YES animated:animated];
|
|
|
}
|
|
- (void)viewWillDisappear:(BOOL)animated {
|
[super viewWillDisappear:animated];
|
[self.navigationController setNavigationBarHidden:NO animated:animated];
|
|
}
|
|
- (void)loadViewConfig {
|
[self.view addSubview:self.viewPPTVNav];
|
self.viewPPTVNav.name = _parms[@"name"];
|
self.viewPPTVNav.content = _parms[@"playUrl"];
|
[self.view addSubview:self.webView];
|
[self.view addSubview:self.viewPPTVPop];
|
[self.view addSubview:self.viewPPTVVip];
|
|
[self.webView addJavascriptObject:[[JSAPI alloc] init] namespace:@"yestv"];
|
[self.webView setDebugMode:true];
|
[self.webView customJavascriptDialogLabelTitles:@{@"alertTitle":@"Notification",@"alertBtn":@"OK"}];
|
|
//192.168.3.135
|
|
NSString *url = self.parms[@"playUrl"];
|
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
|
[self.webView loadRequest:request];
|
|
if (@available(iOS 13, *)) {
|
|
} else {
|
//将要进入全屏
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startFullScreen) name:UIWindowDidResignKeyNotification object:nil];
|
//退出全屏
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endFullScreen) name:UIWindowDidBecomeHiddenNotification object:nil];
|
}
|
|
//[self.webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL];
|
//修改滚动速度
|
}
|
|
-(void)startFullScreen {
|
//[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
|
UIApplication *application = [UIApplication sharedApplication];
|
[application setStatusBarOrientation: UIInterfaceOrientationLandscapeRight];
|
application.keyWindow.transform=CGAffineTransformMakeRotation(M_PI/2);
|
CGRect frame = [UIScreen mainScreen].applicationFrame;
|
application.keyWindow.bounds = CGRectMake(0, 0, frame.size.height + 20, frame.size.width);
|
}
|
|
-(void)endFullScreen {
|
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
|
UIApplication *application = [UIApplication sharedApplication];
|
[application setStatusBarOrientation: UIInterfaceOrientationLandscapeRight];
|
CGRect frame = [UIScreen mainScreen].applicationFrame;
|
application.keyWindow.bounds = CGRectMake(0, 0, frame.size.width, frame.size.height + 20);
|
[UIView animateWithDuration:0 animations:^{
|
application.keyWindow.transform=CGAffineTransformMakeRotation(M_PI * 2);
|
}];
|
}
|
|
//- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
// //网页title
|
// if ([keyPath isEqualToString:@"title"]) {
|
// if (object == self.webView) {
|
// self.viewPPTVNav.name = self.webView.title;
|
//
|
// } else {
|
// [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
// }
|
//
|
// } else {
|
// [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
// }
|
//}
|
|
#pragma mark --------- PPTVDelegate ---------
|
- (void)backVc {
|
[self.navigationController popViewControllerAnimated:YES];
|
}
|
|
- (void)moreSelect {
|
self.viewPPTVPop.hidden = NO;
|
}
|
|
- (void)selectType:(NSString *)type {
|
if ([type isEqualToString:@"刷新"]) {
|
[self.webView reload];
|
|
} else if ([type isEqualToString:@"复制链接"]) {
|
[self copyUrl];
|
|
}else if ([type isEqualToString:@"用其他浏览器打开"]) {
|
if (@available(iOS 10, *)) {
|
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:_content?:@""] options:@{} completionHandler:^(BOOL success) {}];
|
|
} else {
|
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:_content?:@""]];
|
}
|
}
|
}
|
|
- (void)copyUrl {
|
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
|
pasteboard.string = _content?:@"";
|
[SVProgressHUD showWithStatus:@"复制成功"];
|
}
|
|
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
|
|
NSLog(@"");
|
}
|
|
// 页面开始加载时调用
|
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
|
}
|
|
// 页面加载失败时调用
|
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
|
|
}
|
|
// 当内容开始返回时调用
|
- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation {
|
[self performSelector:@selector(afterDelay) withObject:nil afterDelay:0.5];
|
}
|
|
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void(^)(WKNavigationActionPolicy))decisionHandler {
|
|
NSString *strRequest = navigationAction.request.URL.absoluteString;
|
|
if ([strRequest containsString:@"acmd.api.pptv.com"] && [strRequest containsString:@"bwysdqmovie"]) {
|
self.content = strRequest;
|
self.viewPPTVNav.content = strRequest;
|
}
|
|
decisionHandler(WKNavigationActionPolicyAllow);//允许跳转
|
}
|
|
- (void)afterDelay {
|
[self.webView evaluateJavaScript:@"javascript:adPlayFinish()" completionHandler:^(id _Nullable object, NSError * _Nullable error) {}];
|
|
NSString *str = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"js"ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil];
|
[self.webView evaluateJavaScript:str completionHandler:^(id _Nullable object, NSError * _Nullable error) {
|
NSLog(@"");
|
}];
|
}
|
|
- (DWKWebView *)webView {
|
if (!_webView) {
|
// 0.网页配置对象
|
WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
|
// 1.原生与JS交互管理
|
WKUserContentController *userContentController = [[WKUserContentController alloc] init];
|
|
/// 解决循环引用
|
// 0.在viewdisAppear方法中
|
// [self.wkWebview.configuration.userContentController removeScriptMessageHandlerForName:@"ScanAction"];
|
// [userContentController addScriptMessageHandler:self name:@"ScanAction"];
|
|
// 1.继承系统的NSProxy
|
// [userContentController addScriptMessageHandler:(id<WKScriptMessageHandler>)[XPZ_Proxy proxyWithTarget:self] name:@"ScanAction"];
|
|
// 2.自定义NSProxy
|
// [userContentController addScriptMessageHandler:(id<WKScriptMessageHandler>)[XPZ_CustomProxy proxyWithTarget:self] name:@"ScanAction"];
|
// 添加
|
config.userContentController = userContentController;
|
|
// 3.WKWebview设置
|
WKPreferences *prefer = [[WKPreferences alloc] init];
|
//设置是否支持javaScript 默认是支持的
|
prefer.javaScriptEnabled = true;
|
// // 在iOS上默认为NO,表示是否允许不经过用户交互由javaScript自动打开窗口
|
prefer.javaScriptCanOpenWindowsAutomatically = YES;
|
// 添加
|
config.preferences = prefer;
|
config.preferences.minimumFontSize = 0.0f;
|
// 是使用h5的视频播放器在线播放, 还是使用原生播放器全屏播放
|
config.allowsInlineMediaPlayback = YES;
|
//设置视频是否需要用户手动播放 设置为NO则会允许自动播放
|
config.mediaTypesRequiringUserActionForPlayback = YES;
|
//设置是否允许画中画技术 在特定设备上有效
|
config.allowsPictureInPictureMediaPlayback = YES;
|
//设置请求的User-Agent信息中应用程序名称 iOS9后可用
|
config.applicationNameForUserAgent = @"ChinaDailyForiPad";
|
|
config.suppressesIncrementalRendering = YES;
|
|
_webView = [[DWKWebView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.viewPPTVNav.frame), KScreenW, KScreenH - CGRectGetHeight(self.viewPPTVNav.frame)) configuration:config];
|
|
_webView.UIDelegate = self;
|
_webView.navigationDelegate = self;
|
// 是否允许手势左滑返回上一级, 类似导航控制的左滑返回
|
_webView.allowsBackForwardNavigationGestures = YES;
|
//可返回的页面列表, 存储已打开过的网页
|
//WKBackForwardList * backForwardList = [_webView backForwardList];
|
}
|
return _webView;
|
}
|
|
- (PPTVNavView *)viewPPTVNav {
|
if (!_viewPPTVNav) {
|
_viewPPTVNav = [[PPTVNavView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, kStatusBarH + ALNavBarH)];
|
_viewPPTVNav.delegate = self;
|
}
|
return _viewPPTVNav;
|
}
|
|
- (PPTVPppView *)viewPPTVPop {
|
if (!_viewPPTVPop) {
|
_viewPPTVPop = [[PPTVPppView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.viewPPTVNav.frame), KScreenW, KScreenH - CGRectGetHeight(self.viewPPTVNav.frame))];
|
_viewPPTVPop.hidden = YES;
|
_viewPPTVPop.delegate = self;
|
}
|
return _viewPPTVPop;
|
}
|
|
- (PPTVBottomVIpVIew *)viewPPTVVip {
|
if (!_viewPPTVVip) {
|
_viewPPTVVip = [[PPTVBottomVIpVIew alloc] initWithFrame:CGRectMake(0, 0, KScreenW, KScreenH)];
|
//_viewPPTVVip.hidden = YES;
|
// _viewPPTVVip.delegate = self;
|
}
|
return _viewPPTVVip;
|
}
|
@end
|