|
|
@@ -358,19 +358,27 @@ static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
|
|
|
[channel invokeMethod:@"onState" arguments:@{@"type": @"startLoad", @"url": webView.URL.absoluteString}];
|
|
|
}
|
|
|
|
|
|
+- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error {
|
|
|
+ NSString* url = webView.URL == nil ? @"?" : webView.URL.absoluteString;
|
|
|
+
|
|
|
+ [channel invokeMethod:@"onHttpError" arguments:@{@"code": [NSString stringWithFormat:@"%ld", error.code], @"url": url}];
|
|
|
+}
|
|
|
+
|
|
|
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
|
|
|
[channel invokeMethod:@"onState" arguments:@{@"type": @"finishLoad", @"url": webView.URL.absoluteString}];
|
|
|
}
|
|
|
|
|
|
- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error {
|
|
|
- [channel invokeMethod:@"onError" arguments:@{@"code": [NSString stringWithFormat:@"%ld", error.code], @"error": error.localizedDescription}];
|
|
|
+ [channel invokeMethod:@"onHttpError" arguments:@{@"code": [NSString stringWithFormat:@"%ld", error.code], @"error": error.localizedDescription}];
|
|
|
}
|
|
|
|
|
|
- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
|
|
|
if ([navigationResponse.response isKindOfClass:[NSHTTPURLResponse class]]) {
|
|
|
NSHTTPURLResponse * response = (NSHTTPURLResponse *)navigationResponse.response;
|
|
|
|
|
|
- [channel invokeMethod:@"onHttpError" arguments:@{@"code": [NSString stringWithFormat:@"%ld", response.statusCode], @"url": webView.URL.absoluteString}];
|
|
|
+ if (response.statusCode >= 400) {
|
|
|
+ [channel invokeMethod:@"onHttpError" arguments:@{@"code": [NSString stringWithFormat:@"%ld", response.statusCode], @"url": webView.URL.absoluteString}];
|
|
|
+ }
|
|
|
}
|
|
|
decisionHandler(WKNavigationResponsePolicyAllow);
|
|
|
}
|