Commit 98874036 cgx

引入KVOController

1 个父辈 1a253ce3
......@@ -2564,7 +2564,7 @@
"$(PROJECT_DIR)/DreamSleep/Vendors/UMSDK/share/share_ios_6.10.5/SocialLibraries/WeChat/WechatSDK",
"$(PROJECT_DIR)/DreamSleep/Vendors/UMSDK/share/share_ios_6.10.5/SocialLibraries/QQ",
);
MARKETING_VERSION = 2.2.0;
MARKETING_VERSION = 2.0.1;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = (
"$(inherited)",
......@@ -2644,7 +2644,7 @@
"$(PROJECT_DIR)/DreamSleep/Vendors/UMSDK/share/share_ios_6.10.5/SocialLibraries/WeChat/WechatSDK",
"$(PROJECT_DIR)/DreamSleep/Vendors/UMSDK/share/share_ios_6.10.5/SocialLibraries/QQ",
);
MARKETING_VERSION = 2.2.0;
MARKETING_VERSION = 2.0.1;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = (
"$(inherited)",
......@@ -2786,7 +2786,7 @@
"$(PROJECT_DIR)/DreamSleep/Vendors/UMSDK/share/share_ios_6.10.5/SocialLibraries/WeChat/WechatSDK",
"$(PROJECT_DIR)/DreamSleep/Vendors/UMSDK/share/share_ios_6.10.5/SocialLibraries/QQ",
);
MARKETING_VERSION = 2.2.0;
MARKETING_VERSION = 2.0.1;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = (
"$(inherited)",
......
......@@ -47,4 +47,6 @@
#import "NSObject+AutoCancelRequest.h"
#import <KVOController/KVOController.h>
#endif /* PrefixHeader_pch */
......@@ -29,7 +29,9 @@
@property (assign, nonatomic) BOOL webViewLoadTitle;
@end
@implementation DsWebController
@implementation DsWebController {
FBKVOController *_fbKVO;
}
- (instancetype)initWithTitle:(NSString *)title link:(NSString *)link {
if (self = [super init]) {
......@@ -90,7 +92,6 @@
- (void)dealloc {
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"AppModel"];
[self.webView removeObserver:self forKeyPath:@"estimatedProgress"];
}
- (void)closeCurrentPage {
......@@ -99,16 +100,6 @@
}
}
#pragma mark - WKWebView的监听方法
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
if ([keyPath isEqualToString:@"estimatedProgress"]) {
[self.progressView setProgress:self.webView.estimatedProgress animated:YES];
self.progressView.hidden = self.progressView.progress == 1;
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
#pragma mark - WKNavigationDelegate
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(nonnull WKNavigationAction *)navigationAction decisionHandler:(nonnull void (^)(WKNavigationActionPolicy))decisionHandler {
DSLog(@"通用H5页面入口->跳转链接:%@", navigationAction.request.URL.absoluteString);
......@@ -239,10 +230,20 @@
_webView.hidden = YES;
_webView.scrollView.bounces = NO;
_webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
[_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:self.linkUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
self.request = request;
[_webView loadRequest:self.request];
WS(weaksSelf);
_fbKVO = [FBKVOController controllerWithObserver:self];
[_fbKVO observe:_webView keyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSString *,id> * _Nonnull change) {
NSString *changeKeyPath = change[FBKVONotificationKeyPathKey];
if ([changeKeyPath isEqualToString:@"estimatedProgress"]) {
[weaksSelf.progressView setProgress:weaksSelf.webView.estimatedProgress animated:YES];
weaksSelf.progressView.hidden = weaksSelf.progressView.progress == 1;
}
}];
}
return _webView;
}
......
......@@ -24,7 +24,9 @@
@property (assign, nonatomic) BOOL webViewLoadTitle;
@end
@implementation AISleepCoachController
@implementation AISleepCoachController {
FBKVOController *_fbKVO;
}
- (void)viewDidLoad {
[super viewDidLoad];
......@@ -63,7 +65,6 @@
- (void)dealloc {
[self.aiWebView.configuration.userContentController removeScriptMessageHandlerForName:@"AppModel"];
[self.aiWebView removeObserver:self forKeyPath:@"estimatedProgress"];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NeedUpdateAICoach object:nil];
}
......@@ -80,16 +81,6 @@
[self.aiWebView reload];
}
#pragma mark - WKWebView的监听方法
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
if ([keyPath isEqualToString:@"estimatedProgress"]) {
self.progressView.progress = self.aiWebView.estimatedProgress;
if (self.progressView.progress == 1) { self.progressView.hidden = YES; }
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
#pragma mark - WKNavigationDelegate
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(nonnull WKNavigationAction *)navigationAction decisionHandler:(nonnull void (^)(WKNavigationActionPolicy))decisionHandler {
NSString *url = navigationAction.request.URL.absoluteString;
......@@ -263,7 +254,6 @@
_aiWebView.backgroundColor = DSWhite;
_aiWebView.hidden = YES;
_aiWebView.scrollView.bounces = NO;
[_aiWebView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
_aiWebView.navigationDelegate = self;
_aiWebView.scrollView.showsVerticalScrollIndicator = NO;
_aiWebView.scrollView.showsHorizontalScrollIndicator = NO;
......@@ -275,6 +265,16 @@
NSDictionary *dict = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies];
self.request.allHTTPHeaderFields = dict;
[_aiWebView loadRequest:self.request];
WS(weaksSelf);
_fbKVO = [FBKVOController controllerWithObserver:self];
[_fbKVO observe:_aiWebView keyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSString *,id> * _Nonnull change) {
NSString *changeKeyPath = change[FBKVONotificationKeyPathKey];
if ([changeKeyPath isEqualToString:@"estimatedProgress"]) {
weaksSelf.progressView.progress = weaksSelf.aiWebView.estimatedProgress;
if (weaksSelf.progressView.progress == 1) { weaksSelf.progressView.hidden = YES; }
}
}];
}
return _aiWebView;
}
......
......@@ -16,6 +16,7 @@ target 'DreamSleep' do
pod 'IQKeyboardManager', '~> 6.5.10'
pod 'KTVHTTPCache', '~> 2.0.1'
pod 'TZImagePickerController', '~> 3.8.3'
pod 'KVOController', '~> 1.2.0'
end
# AFNetworking (4.0.1)
......
......@@ -36,6 +36,7 @@ PODS:
- CocoaAsyncSocket
- KTVHTTPCache (2.0.1):
- KTVCocoaHTTPServer
- KVOController (1.2.0)
- lottie-ios (2.5.3)
- Masonry (1.1.0)
- MBProgressHUD (1.2.0)
......@@ -64,6 +65,7 @@ DEPENDENCIES:
- FreeStreamer (~> 4.0.0)
- IQKeyboardManager (~> 6.5.10)
- KTVHTTPCache (~> 2.0.1)
- KVOController (~> 1.2.0)
- lottie-ios (~> 2.5.3)
- Masonry (~> 1.1.0)
- MBProgressHUD (~> 1.2.0)
......@@ -83,6 +85,7 @@ SPEC REPOS:
- IQKeyboardManager
- KTVCocoaHTTPServer
- KTVHTTPCache
- KVOController
- lottie-ios
- Masonry
- MBProgressHUD
......@@ -103,6 +106,7 @@ SPEC CHECKSUMS:
IQKeyboardManager: 45a1fa55c1a5b02c61ac0fd7fd5b62bb4ad20d97
KTVCocoaHTTPServer: df8d7b861e603ff8037e9b2138aca2563a6b768d
KTVHTTPCache: 588c3eb16f6bd1e6fde1e230dabfb7bd4e490a4d
KVOController: d72ace34afea42468329623b3379ab3cd1d286b6
lottie-ios: a50d5c0160425cd4b01b852bb9578963e6d92d31
Masonry: 678fab65091a9290e40e2832a55e7ab731aad201
MBProgressHUD: 3ee5efcc380f6a79a7cc9b363dd669c5e1ae7406
......@@ -114,6 +118,6 @@ SPEC CHECKSUMS:
YYModel: 2a7fdd96aaa4b86a824e26d0c517de8928c04b30
YYWebImage: 5f7f36aee2ae293f016d418c7d6ba05c4863e928
PODFILE CHECKSUM: c1c1abe6284d1810dd534fffee52305ff0a63f06
PODFILE CHECKSUM: 319229d796748f474e0ae37b0e38d522e1eeac48
COCOAPODS: 1.11.3
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!