fixed loading error handling for android and iOS

This commit is contained in:
pichillilorenzo 2018-09-22 14:54:21 +02:00
parent eabcb03030
commit 57e1a86bdc
7 changed files with 67 additions and 42 deletions

View File

@ -11,9 +11,12 @@
<component name="ChangeListManager">
<list default="true" id="9b41f7a2-a71e-4923-91fb-249d7815b3e7" name="Default" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java" />
<change beforePath="$PROJECT_DIR$/README.md" afterPath="$PROJECT_DIR$/README.md" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebViewClient.java" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebViewClient.java" />
<change beforePath="$PROJECT_DIR$/example/lib/main.dart" afterPath="$PROJECT_DIR$/example/lib/main.dart" />
<change beforePath="$PROJECT_DIR$/ios/Classes/InAppBrowserWebViewController.swift" afterPath="$PROJECT_DIR$/ios/Classes/InAppBrowserWebViewController.swift" />
<change beforePath="$PROJECT_DIR$/ios/Classes/SwiftFlutterPlugin.swift" afterPath="$PROJECT_DIR$/ios/Classes/SwiftFlutterPlugin.swift" />
<change beforePath="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" afterPath="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" />
</list>
<ignored path="$PROJECT_DIR$/.dart_tool/" />
<ignored path="$PROJECT_DIR$/.idea/" />
@ -33,8 +36,8 @@
<file leaf-file-name="flutter_inappbrowser.dart" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="513">
<caret line="198" column="52" lean-forward="false" selection-start-line="198" selection-start-column="52" selection-end-line="198" selection-end-column="52" />
<state relative-caret-position="270">
<caret line="37" column="27" lean-forward="false" selection-start-line="37" selection-start-column="27" selection-end-line="37" selection-end-column="27" />
<folding>
<element signature="e#814#834#0" expanded="true" />
</folding>
@ -45,8 +48,8 @@
<file leaf-file-name="main.dart" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="141">
<caret line="25" column="21" lean-forward="false" selection-start-line="25" selection-start-column="21" selection-end-line="25" selection-end-column="21" />
<state relative-caret-position="243">
<caret line="20" column="19" lean-forward="true" selection-start-line="20" selection-start-column="19" selection-end-line="20" selection-end-column="19" />
<folding />
</state>
</provider>
@ -128,13 +131,13 @@
<option value="$PROJECT_DIR$/LICENSE" />
<option value="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserDialog.java" />
<option value="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserClient.java" />
<option value="$PROJECT_DIR$/README.md" />
<option value="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowser.java" />
<option value="$PROJECT_DIR$/example/ios/Podfile" />
<option value="$PROJECT_DIR$/ios/flutter_inappbrowser.podspec" />
<option value="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" />
<option value="$PROJECT_DIR$/android/build.gradle" />
<option value="$PROJECT_DIR$/pubspec.yaml" />
<option value="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" />
<option value="$PROJECT_DIR$/README.md" />
<option value="$PROJECT_DIR$/example/lib/main.dart" />
</list>
</option>
@ -419,6 +422,7 @@
</component>
<component name="ToolWindowManager">
<frame x="288" y="23" width="1632" height="1057" extended-state="0" />
<editor active="true" />
<layout>
<window_info id="Android Profiler" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Build Variants" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
@ -436,7 +440,7 @@
<window_info id="Palette&#9;" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Image Layers" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Capture Analysis" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.36208734" sideWeight="0.4973545" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.36208734" sideWeight="0.4973545" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3258786" sideWeight="0.4973545" order="10" side_tool="false" content_ui="tabs" />
<window_info id="Captures" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32936507" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
@ -696,16 +700,6 @@
</entry>
<entry file="file://$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserClient.java" />
<entry file="file://$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserDialog.java" />
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="106">
<caret line="94" column="0" lean-forward="true" selection-start-line="94" selection-start-column="0" selection-end-line="94" selection-end-column="0" />
</first_editor>
<second_editor />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/ios/Flutter/Release.xcconfig">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
@ -832,10 +826,42 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="416">
<caret line="41" column="11" lean-forward="true" selection-start-line="41" selection-start-column="11" selection-end-line="41" selection-end-column="11" />
<folding>
<marker date="1537620468637" expanded="false" signature="933:1031" ph="..." />
<marker date="1537620468637" expanded="true" signature="1075:1571" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1121:1189" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1233:1300" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1371:1475" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1505:1568" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1698:1763" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1804:2315" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1838:1866" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1917:2313" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1945:2308" ph="(...)" />
<marker date="1537620468637" expanded="true" signature="1971:2301" ph="(...)" />
<marker date="1537620468637" expanded="true" signature="1999:2082" ph="(...)" />
<marker date="1537620468637" expanded="true" signature="2028:2071" ph="(...)" />
<marker date="1537620468637" expanded="true" signature="2108:2292" ph="(...)" />
<marker date="1537620468637" expanded="true" signature="2143:2281" ph="(...)" />
<marker date="1537620468637" expanded="true" signature="10474:10507" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="10626:10658" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="10818:10850" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="10946:10971" ph="{...}" />
</folding>
</first_editor>
<second_editor />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="513">
<caret line="198" column="52" lean-forward="false" selection-start-line="198" selection-start-column="52" selection-end-line="198" selection-end-column="52" />
<state relative-caret-position="270">
<caret line="37" column="27" lean-forward="false" selection-start-line="37" selection-start-column="27" selection-end-line="37" selection-end-column="27" />
<folding>
<element signature="e#814#834#0" expanded="true" />
</folding>
@ -844,8 +870,8 @@
</entry>
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="141">
<caret line="25" column="21" lean-forward="false" selection-start-line="25" selection-start-column="21" selection-end-line="25" selection-end-column="21" />
<state relative-caret-position="243">
<caret line="20" column="19" lean-forward="true" selection-start-line="20" selection-start-column="19" selection-end-line="20" selection-end-column="19" />
<folding />
</state>
</provider>

View File

@ -40,8 +40,8 @@ class MyInAppBrowser extends InAppBrowser {
}
@override
void onLoadError(String url, String code, String message) {
super.onLoadStop(url);
void onLoadError(String url, int code, String message) {
super.onLoadError(url, code, message);
print("\n\nCan't load $url.. Error: $message\n\n");
}

View File

@ -149,8 +149,7 @@ public class InAppBrowserWebViewClient extends WebViewClient {
Map<String, Object> obj = new HashMap<>();
obj.put("url", error.getUrl());
obj.put("code", 0);
obj.put("sslerror", error.getPrimaryError());
obj.put("code", error.getPrimaryError());
String message;
switch (error.getPrimaryError()) {
case SslError.SSL_DATE_INVALID:
@ -173,7 +172,7 @@ public class InAppBrowserWebViewClient extends WebViewClient {
message = "The certificate authority is not trusted";
break;
}
obj.put("message", message);
obj.put("message", "SslError: " + message);
InAppBrowserFlutterPlugin.channel.invokeMethod("loaderror", obj);
handler.cancel();

View File

@ -43,8 +43,8 @@ class MyInAppBrowser extends InAppBrowser {
}
@override
void onLoadError(String url, String code, String message) {
super.onLoadStop(url);
void onLoadError(String url, int code, String message) {
super.onLoadError(url, code, message);
print("\n\nCan't load $url.. Error: $message\n\n");
}

View File

@ -489,21 +489,21 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
navigationDelegate?.webViewDidFinishLoad(webView)
}
func webView(_ webView: WKWebView,
didFailProvisionalNavigation navigation: WKNavigation!,
withError error: Error) {
print("webView:didFailProvisionalNavigationWithError - \(Int(error._code)): \(error.localizedDescription)")
backButton.isEnabled = webView.canGoBack
forwardButton.isEnabled = webView.canGoForward
spinner.stopAnimating()
navigationDelegate?.webView(webView, didFailLoadWithError: error)
}
// func webView(_ webView: WKWebView,
// didFailProvisionalNavigation navigation: WKNavigation!,
// withError error: Error) {
// print("webView:didFailProvisionalNavigationWithError - \(Int(error._code)): \(error.localizedDescription)")
// backButton.isEnabled = webView.canGoBack
// forwardButton.isEnabled = webView.canGoForward
// spinner.stopAnimating()
// navigationDelegate?.webView(webView, didFailLoadWithError: error)
// }
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
print("webView:didFailNavigationWithError - \(Int(error._code)): \(error.localizedDescription)")
backButton.isEnabled = webView.canGoBack
forwardButton.isEnabled = webView.canGoForward
spinner.stopAnimating()
navigationDelegate?.webView(webView, didFailLoadWithError: error)
navigationDelegate?.webViewDidFailLoadWithError(webView, error: error)
}
}

View File

@ -325,7 +325,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
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 arguments = ["url": url, "code": error._code, "message": error.localizedDescription] as [String : Any]
channel.invokeMethod("loaderror", arguments: arguments)

View File

@ -44,7 +44,7 @@ class InAppBrowser {
break;
case "loaderror":
String url = call.arguments["url"];
String code = call.arguments["code"];
int code = call.arguments["code"];
String message = call.arguments["message"];
onLoadError(url, code, message);
break;
@ -212,7 +212,7 @@ class InAppBrowser {
}
///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) {
}