智莺生活APP的阿里百川 Flutter 插件
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

90 righe
2.8 KiB

  1. //
  2. // ALiTradeWantViewController.m
  3. // ALiSDKAPIDemo
  4. //
  5. // Created by com.alibaba on 16/6/1.
  6. // Copyright © 2016年 alibaba. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import "ALiTradeWebViewController.h"
  10. #import <AlibcTradeSDK/AlibcTradeSDK.h>
  11. //#import "ALiCartService.h"
  12. @interface ALiTradeWebViewController()
  13. @end
  14. @implementation ALiTradeWebViewController
  15. - (instancetype)init
  16. {
  17. self = [super init];
  18. if (self) {
  19. _webView = [[WKWebView alloc]initWithFrame:self.view.bounds];
  20. _webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  21. _webView.scrollView.scrollEnabled = YES;
  22. // _webView.navigationDelegate = self;
  23. _webView.navigationDelegate = self;
  24. _webView.UIDelegate = self;
  25. [_webView addObserver:self forKeyPath:@"URL" options:NSKeyValueObservingOptionNew context:nil];
  26. [self.view addSubview:_webView];
  27. }
  28. return self;
  29. }
  30. - (void)viewDidLoad
  31. {
  32. [super viewDidLoad];
  33. self.title=@"淘你喜欢";
  34. [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
  35. forBarMetrics:UIBarMetricsDefault];
  36. }
  37. -(void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void*)context{
  38. NSLog(@"url == %@",_webView.URL.absoluteString);
  39. NSString *urlStr = _webView.URL.absoluteString;
  40. NSRange range;
  41. range = [urlStr rangeOfString:@"access_token"];
  42. if (range.location != NSNotFound) {
  43. NSString *accessString = [urlStr substringFromIndex:range.location];
  44. // 截止到&
  45. NSRange range2 = [accessString rangeOfString: @"&"];
  46. NSString *access_token_string = [accessString substringWithRange:NSMakeRange(0,range2.location)];
  47. NSArray *array = [access_token_string componentsSeparatedByString:@"="];
  48. NSString *access_token = array[1];
  49. NSLog(@"%@",access_token);
  50. // 跳转回去
  51. [[NSNotificationCenter defaultCenter] postNotificationName:@"getAccessToken" object:access_token];
  52. [self.navigationController popViewControllerAnimated:YES];
  53. }else{
  54. NSLog(@"Not Found");
  55. }
  56. }
  57. -(void)dealloc
  58. {
  59. NSLog(@"dealloc view");
  60. [_webView removeObserver:self forKeyPath:@"URL"];
  61. _webView = nil;
  62. }
  63. -(void)setOpenUrl:(NSString *)openUrl {
  64. [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:openUrl]]];
  65. }
  66. -(WKWebView *)getWebView{
  67. return _webView;
  68. }
  69. #pragma mark - WKNavigationDelegate
  70. - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
  71. // 重定向
  72. decisionHandler(WKNavigationActionPolicyAllow);
  73. }
  74. @end