123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- //
- // KBShopPushWebViewController.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/11/5.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "KBShopPushWebViewController.h"
- #import <AlibcTradeSDK/AlibcTradeSDK.h>
- #import <AlibabaAuthSDK/ALBBSession.h>
- #import <AlibabaAuthSDK/ALBBSDK.h>
- #import "WebviewProgressLine.h"
- @interface KBShopPushWebViewController ()<UIWebViewDelegate>
- @property (nonatomic, strong) UIWebView *webView;
- @property (nonatomic, strong) UIButton *backButton;
- /** 加载进度条 */
- @property (nonatomic,strong) WebviewProgressLine *progressLine;
- @end
- @implementation KBShopPushWebViewController
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self configWebView];
- [self configNavigationBar];
- [self openUrl];
- }
- - (void)configWebView {
-
- self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight)];
- self.webView.delegate = self;
- [self.view addSubview:self.webView];
- }
- - (void)configNavigationBar {
-
- self.view.backgroundColor = [UIColor whiteColor];
-
- self.navigationBar.showNavigationBarBottomLine = YES;
-
-
- [self.navigationBar setCustomLeftButtons:@[self.backButton]];
- self.progressLine = [[WebviewProgressLine alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, 3)];
- self.progressLine.lineColor = [UIColor YHColorWithHex:0xCC0E0E];
- [self.view addSubview:self.progressLine];
- }
- - (void)backAction {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)openUrl {
- id<AlibcTradePage> page = [AlibcTradePageFactory page:self.url];
- [self openWebViewByPage:page];
- }
- - (void)openWebViewByPage:(id<AlibcTradePage>)page {
- //淘客信息
- AlibcTradeTaokeParams *taoKeParams=[[AlibcTradeTaokeParams alloc] init];
- taoKeParams.pid = ALTK_PID;
- //打开方式
- AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
-
- showParam.openType = AlibcOpenTypeH5;
-
- [[AlibcTradeSDK sharedInstance].tradeService show:self webView:self.webView page:page showParams:showParam taoKeParams:taoKeParams trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
-
- } tradeProcessFailedCallback:^(NSError * _Nullable error) {
-
- }];
- self.webView.delegate = self;
- }
- #pragma mark -------------- UIWebView delegate --------
- - (void)webViewDidStartLoad:(UIWebView *)webView {
- [self.progressLine startLoadingAnimation];
- }
- #pragma mark -- 拦截webview用户触击了一个链接
- - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
- {
- //判断是否是单击
- if (navigationType == UIWebViewNavigationTypeLinkClicked)
- {
- NSString *url = [request.URL absoluteString];
-
- //拦截链接跳转到动态详情
- if ([url rangeOfString:@"http"].location != NSNotFound)
- {
- //跳转到你想跳转的页面
-
- KBShopPushWebViewController *web = [[KBShopPushWebViewController alloc] init];
- web.url = url;
- [self.navigationController pushViewController:web animated:YES];
-
- return NO; //返回NO,此页面的链接点击不会继续执行,只会执行跳转到你想跳转的页面
- }
- }
- return YES;
- }
- - (void)webViewDidFinishLoad:(UIWebView *)webView {
- NSString *title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
- [self.navigationBar setNavTitle:title];
- [self.progressLine endLoadingAnimation];
- }
- - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
- [self.progressLine endLoadingAnimation];
- }
- #pragma mark ------
- - (UIButton *)backButton {
- if (!_backButton) {
- _backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
- [_backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
- [_backButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
- }
- return _backButton;
- }
- @end
|