优化
This commit is contained in:
@@ -156,4 +156,4 @@ SPEC CHECKSUMS:
|
||||
|
||||
PODFILE CHECKSUM: cc88fa05da662ee682fc0eeb502faab221faa032
|
||||
|
||||
COCOAPODS: 1.14.2
|
||||
COCOAPODS: 1.12.1
|
||||
|
@@ -98,7 +98,29 @@ NSString * const kJSGetUid = @"getUid";
|
||||
}
|
||||
}];
|
||||
}
|
||||
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler{
|
||||
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSURLCredential *card = [[NSURLCredential alloc]initWithTrust:challenge.protectionSpace.serverTrust];
|
||||
completionHandler(NSURLSessionAuthChallengeUseCredential,card);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
//加载完成
|
||||
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
|
||||
//加载完成后隐藏progressView
|
||||
self.progressView.hidden = YES;
|
||||
|
||||
}
|
||||
|
||||
//加载失败
|
||||
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error {
|
||||
//加载失败同样需要隐藏progressView
|
||||
self.progressView.hidden = YES;
|
||||
|
||||
}
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
|
||||
if ([keyPath isEqualToString:@"estimatedProgress"]) {
|
||||
self.progressView.progress = self.webview.estimatedProgress;
|
||||
@@ -155,21 +177,19 @@ NSString * const kJSGetUid = @"getUid";
|
||||
if (![_url hasPrefix:@"http"] && ![_url hasPrefix:@"https"]){
|
||||
_url = [NSString stringWithFormat:@"%@/%@", API_HOST_H5_URL, _url];
|
||||
}
|
||||
if (![_url containsString:@"alipayh5"]) {
|
||||
|
||||
if (![_url containsString:@"?"]) {
|
||||
_url = [NSString stringWithFormat:@"%@?platform=%@", _url, [YYUtility appName]];
|
||||
} else {
|
||||
_url = [NSString stringWithFormat:@"%@&platform=%@", _url, [YYUtility appName]];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 去掉 urlString 中的空格。
|
||||
NSString *noSpaceTextUrl = [_url stringByReplacingOccurrencesOfString:@" " withString:@""];
|
||||
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:noSpaceTextUrl]];
|
||||
if ([_url containsString:@"wx.tenpay"]) {
|
||||
[request setValue:[NSString stringWithFormat:@"xdx.%@://", CompanyFirstDomainByWeChatRegister] forHTTPHeaderField:@"Referer"];
|
||||
}
|
||||
|
||||
[self.webview loadRequest:request];
|
||||
}
|
||||
|
||||
@@ -215,7 +235,7 @@ NSString * const kJSGetUid = @"getUid";
|
||||
|
||||
CGSize size = [UIScreen mainScreen].bounds.size;
|
||||
_webview = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, size.width,size.height) configuration:configuration];
|
||||
|
||||
|
||||
_webview.navigationDelegate = self;
|
||||
//添加KVO,WKWebView有一个属性estimatedProgress,就是当前网页加载的进度,所以监听这个属性
|
||||
[_webview addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
|
||||
|
Reference in New Issue
Block a user