263 lines
9.6 KiB
Objective-C
263 lines
9.6 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 <AlibcTradeSDK/AlibcTradeSDK.h>
|
|
#import "IfishAlibcWebViewController.h"
|
|
//#import "NJKWebViewProgressView.h"
|
|
//#import "NJKWebViewProgress.h"
|
|
@interface PushMasssageWebViewController ()<WKUIDelegate,WKNavigationDelegate>
|
|
{
|
|
// NJKWebViewProgressView *_progressView;
|
|
// NJKWebViewProgress *_progressProxy;
|
|
}
|
|
//@property(nonatomic,strong)UIWebView*myWebView;
|
|
Strong WKWebView *webView;
|
|
Strong UIProgressView *wkProgressView;
|
|
@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 creatWkwebView];
|
|
|
|
[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
|
|
{
|
|
|
|
self.webView = [[WKWebView alloc]init];
|
|
self.webView.UIDelegate = self;
|
|
self.webView.navigationDelegate = self;
|
|
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.pushlink]]];
|
|
[self.view addSubview:self.webView];
|
|
|
|
self.wkProgressView = [[UIProgressView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 2)];
|
|
self.wkProgressView.progressTintColor = [UIColor greenColor];
|
|
[self.view addSubview:self.wkProgressView];
|
|
|
|
// 给webview添加监听
|
|
[self.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];
|
|
|
|
[self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self.view);
|
|
}];
|
|
}
|
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
|
|
if ([keyPath isEqual:@"estimatedProgress"] && object == self.webView) {
|
|
[self.wkProgressView setAlpha:1.0f];
|
|
[self.wkProgressView setProgress:self.webView.estimatedProgress animated:YES];
|
|
if (self.webView.estimatedProgress >= 1.0f) {
|
|
[UIView animateWithDuration:0.3 delay:0.3 options:UIViewAnimationOptionCurveEaseOut animations:^{
|
|
[self.wkProgressView setAlpha:0.0f];
|
|
} completion:^(BOOL finished) {
|
|
[self.wkProgressView setProgress:0.0f animated:YES];
|
|
}];
|
|
}
|
|
}else{
|
|
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
|
}
|
|
}
|
|
|
|
- (void)dealloc{
|
|
[self.webView removeObserver:self forKeyPath:@"estimatedProgress"];
|
|
[self.webView setNavigationDelegate:nil];
|
|
[self.webView setUIDelegate:nil];
|
|
}
|
|
|
|
- (void)webView:(WKWebView*)webView decidePolicyForNavigationAction:(WKNavigationAction*)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
|
|
{
|
|
if ([navigationAction.request.URL.absoluteString containsString:@"taobao"])
|
|
{
|
|
|
|
//535991514644
|
|
//根据商品ID
|
|
//id<AlibcTradePage> page = [AlibcTradePageFactory itemDetailPage: @"535991514644"];
|
|
//根据链接打开页面
|
|
id<AlibcTradePage> page = [AlibcTradePageFactory page:navigationAction.request.URL.absoluteString ];
|
|
AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
|
|
//app 内闭环交易 强制H5 打开
|
|
showParam.openType = AlibcOpenTypeNative;
|
|
|
|
//AlibcWebViewController* myView = [[AlibcWebViewController alloc] init];
|
|
//自定义web
|
|
IfishAlibcWebViewController* myView = [[IfishAlibcWebViewController alloc] init];
|
|
NSInteger ret = [[AlibcTradeSDK sharedInstance].tradeService show:self.navigationController webView:myView.webView page:page showParams:showParam taoKeParams:nil trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
|
|
|
|
} tradeProcessFailedCallback:^(NSError * _Nullable error) {
|
|
|
|
}]; //返回1,说明h5打开,否则不应该展示页面
|
|
|
|
|
|
if (ret == 1) {
|
|
|
|
self.hidesBottomBarWhenPushed = YES;
|
|
[self.navigationController pushViewController:myView animated:YES];
|
|
}
|
|
decisionHandler(WKNavigationActionPolicyCancel);
|
|
}
|
|
else
|
|
{
|
|
decisionHandler(WKNavigationActionPolicyAllow);
|
|
}
|
|
}
|
|
// 页面开始加载时调用
|
|
- (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
|