123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- //
- // DRWebPageViewController.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/1/31.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "DRWebPageViewController.h"
- #import <AlibcTradeSDK/AlibcTradeSDK.h>
- #import <AlibabaAuthSDK/ALBBSession.h>
- #import <AlibabaAuthSDK/ALBBSDK.h>
- #import "DRTaobaoAuthorView.h"
- @interface DRWebPageViewController ()<UIWebViewDelegate>
- @property (nonatomic, strong) UIButton *backButton;
- @property (nonatomic, strong) UIButton *closeButton;
- @property (nonatomic, strong) DRTaobaoAuthorView *authorView;
- @end
- @implementation DRWebPageViewController
- - (instancetype)init {
- self = [super init];
- if (self) {
- [self configWebView];
- }
- return self;
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- [SVProgressHUD dismiss];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- [self configTaobaoAuthorView];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self initHUD];
- [self configNavigationBar];
-
- }
- - (void)configTaobaoAuthorView {
- if ([[ALBBSession sharedInstance] isLogin]){
- [self openAliMyOrderWebView];
- self.webView.hidden = NO;
- self.authorView.hidden = YES;
- }else {
- self.webView.hidden = YES;
- self.authorView.hidden = NO;
-
- }
- }
- - (void)initHUD {
- [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
- [SVProgressHUD setForegroundColor:[UIColor YHColorWithHex:0xff2420]];
- [SVProgressHUD setBackgroundColor:[UIColor YHColorWithHex:0xf5f4f4]];
-
- }
- - (void)configWebView {
-
- self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight)];
- self.webView.delegate = self;
- [self.view addSubview:self.webView];
- self.authorView = [[DRTaobaoAuthorView alloc] initWithFrame:self.webView.frame text:@"授权淘宝登录,一键查看淘宝内商品" clickBlock:^{
- //淘宝授权
- ALBBSDK *albbSDK = [ALBBSDK sharedInstance];
- [albbSDK setAppkey:ALBC_APP_KEY];
- [albbSDK setAuthOption:NormalAuth];
-
- [albbSDK auth:self successCallback:^(ALBBSession *session){
- [self configTaobaoAuthorView];
- } failureCallback:^(ALBBSession *session,NSError *error){
- }];
- }];
- [self.view addSubview:self.authorView];
- }
- - (void)configNavigationBar {
-
- self.view.backgroundColor = [UIColor whiteColor];
-
- self.navigationBar.showNavigationBarBottomLine = YES;
-
-
- [self.navigationBar setCustomLeftButtons:@[self.backButton]];
-
- }
- - (void)backAction {
- if (self.webView.canGoBack) {
- [self.webView goBack];
- }else{
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- - (void)closeAction {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)updateNavigationBarButtons {
- if (self.webView.canGoBack) {
- [self.navigationBar setCustomLeftButtons:@[self.backButton,self.closeButton]];
- }else {
- [self.navigationBar setCustomLeftButtons:@[self.backButton]];
- }
- }
- - (void)openAliMyOrderWebView {
- [SVProgressHUD show];
-
- switch (self.openPage) {
- case AlibcOpenPageShopCar:
- {
- id<AlibcTradePage> page = [AlibcTradePageFactory myCartsPage];
- [self openWebViewByPage:page];
- }
-
- break;
- case AlibcOpenPageMyOrder:
- {
- id<AlibcTradePage> page = [AlibcTradePageFactory myOrdersPage:0 isAllOrder:YES];
- [self openWebViewByPage:page];
- }
- break;
-
- default:
- {
- id<AlibcTradePage> page = [AlibcTradePageFactory myOrdersPage:0 isAllOrder:YES];
- [self openWebViewByPage:page];
- }
- break;
- }
-
-
- }
- - (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)webViewDidFinishLoad:(UIWebView *)webView {
- [self updateNavigationBarButtons];
- [SVProgressHUD dismiss];
- // NSString *jsToGetHTMLSource = @"document.getElementsByTagName('html')[0].innerHTML";
- //
- // NSString *HTMLSource = [self.webView stringByEvaluatingJavaScriptFromString:jsToGetHTMLSource];
- //
- // NSLog(@"------------:%@",HTMLSource);
- }
- - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
- [SVProgressHUD dismiss];
- }
- #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;
- }
- - (UIButton *)closeButton {
- if (!_closeButton) {
- _closeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
- [_closeButton setImage:[UIImage imageNamed:@"close_web"] forState:UIControlStateNormal];
- [_closeButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
- }
- return _closeButton;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|