ifish/Ifish/controllers/IfishTabControllers/消息/PushMasssageWebViewControll...

194 lines
6.4 KiB
Objective-C

//
// PushMasssageWebViewController.m
// Ifish
//
// Created by imac on 16/8/11.
// Copyright © 2016年 lianxiang. All rights reserved.
//
#import "PushMasssageWebViewController.h"
#import <WebKit/WebKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import "NJKWebViewProgressView.h"
#import "NJKWebViewProgress.h"
@interface PushMasssageWebViewController ()<NJKWebViewProgressDelegate,UIWebViewDelegate>
{
NJKWebViewProgressView *_progressView;
NJKWebViewProgress *_progressProxy;
}
@property(nonatomic,strong)UIWebView*myWebView;
@property(nonatomic,strong)UIActivityIndicatorView*indicator;
@end
@implementation PushMasssageWebViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self addTitleViewWithTitle:self.pushtitle];
[self creatwebView];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault];
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
{
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
}
// NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
// for (NSHTTPCookie *cookie in [cookieJar cookies]) {
// NSLog(@"cookie获取:%@", cookie);
// }
}
-(void)setNewCoookie
{
NSMutableDictionary *cookieProperties = [NSMutableDictionary dictionary];
[cookieProperties setObject:@"cna" forKey:NSHTTPCookieName];
[cookieProperties setObject:@"Obb8EFU60QACAWVR2zjjuuB+" forKey:NSHTTPCookieValue];
[cookieProperties setObject:@".youku.com" forKey:NSHTTPCookieDomain];
[cookieProperties setObject:@".youku.com" forKey:NSHTTPCookieOriginURL];
[cookieProperties setObject:@"/" forKey:NSHTTPCookiePath];
[cookieProperties setObject:@"0" forKey:NSHTTPCookieVersion];
NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
}
-(void)initWebView
{
self.myWebView=[[UIWebView alloc]initWithFrame:self.view.bounds];
NSString*filepath=[[NSBundle mainBundle]pathForResource:@"shuomingshu" ofType:@"html"];
NSString*html=[NSString stringWithContentsOfFile:filepath encoding:NSUTF8StringEncoding error:nil];
[self.myWebView loadHTMLString:html baseURL:[NSURL URLWithString:filepath]];
[self.view addSubview:self.myWebView];
}
#pragma mark - WKWeb IOS 8之后用
-(void)creatWkwebView
{
WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
//NSString*url=[NSString stringWithFormat:@"http://www.baidu.com"];
//NSURLRequest*requst=[NSURLRequest requestWithURL:[NSURL URLWithString:url]];
NSURLRequest*requst=[NSURLRequest requestWithURL:[NSURL URLWithString:self.pushlink]];
[webView loadRequest:requst];
[self.view addSubview:webView];
//webView.navigationDelegate = self;
}
// 页面开始加载时调用
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation
{
[_indicator startAnimating];
}
// 当内容开始返回时调用
- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation{
}
// 页面加载完成之后调用
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
[_indicator stopAnimating];
}
// 页面加载失败时调用
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation{
[_indicator stopAnimating];
}
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController.navigationBar addSubview:_progressView];
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[_progressView removeFromSuperview];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)creatwebView{
self.myWebView.opaque=NO;
self.myWebView.backgroundColor=[UIColor clearColor];
self.myWebView=[[UIWebView alloc]initWithFrame:self.view.bounds];
[self.view addSubview:self.myWebView];
//self.myWebView.delegate=self;
_progressProxy = [[NJKWebViewProgress alloc] init]; // instance variable
self.myWebView.delegate = _progressProxy;
_progressProxy.webViewProxyDelegate = self;
_progressProxy.progressDelegate = self;
CGFloat progressBarHeight = 2.f;
CGRect navigationBarBounds = self.navigationController.navigationBar.bounds;
CGRect barFrame = CGRectMake(0, navigationBarBounds.size.height - progressBarHeight, navigationBarBounds.size.width, progressBarHeight);
_progressView = [[NJKWebViewProgressView alloc] initWithFrame:barFrame];
_progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
NSURLRequest*requst=[NSURLRequest requestWithURL:[NSURL URLWithString:self.pushlink]];
//NSString*url=[NSString stringWithFormat:@"https://bg.zhangxinyanv5.top/ueditorHtml/1484032071200.html"];
//NSURLRequest*requst=[NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[self.myWebView loadRequest:requst];
}
-(void)webViewDidStartLoad:(UIWebView *)webView{
[_indicator startAnimating];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
[_indicator stopAnimating];
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
[_indicator stopAnimating];
}
-(void)initIndicatorView{
_indicator=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
_indicator.frame=CGRectMake(0.f,0.f,100.f, 100.f);
_indicator.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
_indicator.center=self.view.center;
_indicator.layer.masksToBounds=YES;
_indicator.layer.cornerRadius=5;
[self.view addSubview:_indicator];
}
#pragma mark - NJKWebViewProgressDelegate
-(void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
{
[_progressView setProgress:progress animated:YES];
//self.title = [self.myWebView stringByEvaluatingJavaScriptFromString:@"document.title"];
}
@end