智莺生活APP的阿里百川 Flutter 插件
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

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