Commit 57e1a86b authored by pichillilorenzo's avatar pichillilorenzo

fixed loading error handling for android and iOS

parent eabcb030
This diff is collapsed.
...@@ -40,8 +40,8 @@ class MyInAppBrowser extends InAppBrowser { ...@@ -40,8 +40,8 @@ class MyInAppBrowser extends InAppBrowser {
} }
@override @override
void onLoadError(String url, String code, String message) { void onLoadError(String url, int code, String message) {
super.onLoadStop(url); super.onLoadError(url, code, message);
print("\n\nCan't load $url.. Error: $message\n\n"); print("\n\nCan't load $url.. Error: $message\n\n");
} }
......
...@@ -149,8 +149,7 @@ public class InAppBrowserWebViewClient extends WebViewClient { ...@@ -149,8 +149,7 @@ public class InAppBrowserWebViewClient extends WebViewClient {
Map<String, Object> obj = new HashMap<>(); Map<String, Object> obj = new HashMap<>();
obj.put("url", error.getUrl()); obj.put("url", error.getUrl());
obj.put("code", 0); obj.put("code", error.getPrimaryError());
obj.put("sslerror", error.getPrimaryError());
String message; String message;
switch (error.getPrimaryError()) { switch (error.getPrimaryError()) {
case SslError.SSL_DATE_INVALID: case SslError.SSL_DATE_INVALID:
...@@ -173,7 +172,7 @@ public class InAppBrowserWebViewClient extends WebViewClient { ...@@ -173,7 +172,7 @@ public class InAppBrowserWebViewClient extends WebViewClient {
message = "The certificate authority is not trusted"; message = "The certificate authority is not trusted";
break; break;
} }
obj.put("message", message); obj.put("message", "SslError: " + message);
InAppBrowserFlutterPlugin.channel.invokeMethod("loaderror", obj); InAppBrowserFlutterPlugin.channel.invokeMethod("loaderror", obj);
handler.cancel(); handler.cancel();
......
...@@ -43,8 +43,8 @@ class MyInAppBrowser extends InAppBrowser { ...@@ -43,8 +43,8 @@ class MyInAppBrowser extends InAppBrowser {
} }
@override @override
void onLoadError(String url, String code, String message) { void onLoadError(String url, int code, String message) {
super.onLoadStop(url); super.onLoadError(url, code, message);
print("\n\nCan't load $url.. Error: $message\n\n"); print("\n\nCan't load $url.. Error: $message\n\n");
} }
......
...@@ -489,21 +489,21 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio ...@@ -489,21 +489,21 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
navigationDelegate?.webViewDidFinishLoad(webView) navigationDelegate?.webViewDidFinishLoad(webView)
} }
func webView(_ webView: WKWebView, // func webView(_ webView: WKWebView,
didFailProvisionalNavigation navigation: WKNavigation!, // didFailProvisionalNavigation navigation: WKNavigation!,
withError error: Error) { // withError error: Error) {
print("webView:didFailProvisionalNavigationWithError - \(Int(error._code)): \(error.localizedDescription)") // print("webView:didFailProvisionalNavigationWithError - \(Int(error._code)): \(error.localizedDescription)")
backButton.isEnabled = webView.canGoBack // backButton.isEnabled = webView.canGoBack
forwardButton.isEnabled = webView.canGoForward // forwardButton.isEnabled = webView.canGoForward
spinner.stopAnimating() // spinner.stopAnimating()
navigationDelegate?.webView(webView, didFailLoadWithError: error) // navigationDelegate?.webView(webView, didFailLoadWithError: error)
} // }
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) { func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
print("webView:didFailNavigationWithError - \(Int(error._code)): \(error.localizedDescription)") print("webView:didFailNavigationWithError - \(Int(error._code)): \(error.localizedDescription)")
backButton.isEnabled = webView.canGoBack backButton.isEnabled = webView.canGoBack
forwardButton.isEnabled = webView.canGoForward forwardButton.isEnabled = webView.canGoForward
spinner.stopAnimating() spinner.stopAnimating()
navigationDelegate?.webView(webView, didFailLoadWithError: error) navigationDelegate?.webViewDidFailLoadWithError(webView, error: error)
} }
} }
...@@ -325,7 +325,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { ...@@ -325,7 +325,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
channel.invokeMethod("loadstop", arguments: ["url": url]) channel.invokeMethod("loadstop", arguments: ["url": url])
} }
func webView(_ webView: WKWebView, didFailLoadWithError error: Error) { func webViewDidFailLoadWithError(_ webView: WKWebView, error: Error) {
let url: String = webViewController!.currentURL!.absoluteString let url: String = webViewController!.currentURL!.absoluteString
let arguments = ["url": url, "code": error._code, "message": error.localizedDescription] as [String : Any] let arguments = ["url": url, "code": error._code, "message": error.localizedDescription] as [String : Any]
channel.invokeMethod("loaderror", arguments: arguments) channel.invokeMethod("loaderror", arguments: arguments)
......
...@@ -44,7 +44,7 @@ class InAppBrowser { ...@@ -44,7 +44,7 @@ class InAppBrowser {
break; break;
case "loaderror": case "loaderror":
String url = call.arguments["url"]; String url = call.arguments["url"];
String code = call.arguments["code"]; int code = call.arguments["code"];
String message = call.arguments["message"]; String message = call.arguments["message"];
onLoadError(url, code, message); onLoadError(url, code, message);
break; break;
...@@ -212,7 +212,7 @@ class InAppBrowser { ...@@ -212,7 +212,7 @@ class InAppBrowser {
} }
///Event fires when the [InAppBrowser] encounters an error loading an [url]. ///Event fires when the [InAppBrowser] encounters an error loading an [url].
void onLoadError(String url, String code, String message) { void onLoadError(String url, int code, String message) {
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment