From 428ecf7a311ce2d715d57e0e12caa83e2199d4b2 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Sat, 23 May 2020 12:32:27 +0200 Subject: [PATCH] updated README.md, fix #358 --- CHANGELOG.md | 1 + README.md | 30 +++++++++++--- example/.flutter-plugins-dependencies | 2 +- example/ios/Runner.xcodeproj/project.pbxproj | 10 +---- .../lib/in_app_browser_example.screen.dart | 41 ++++++++++++------- ios/Classes/InAppBrowserManager.swift | 4 +- pubspec.yaml | 2 +- 7 files changed, 59 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e02ff04e..92d09120 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Added `onEnterFullscreen`, `onExitFullscreen` webview events - Fixed `Print preview is not working? java.lang.IllegalStateException: Can print only from an activity` [#128](https://github.com/pichillilorenzo/flutter_inappwebview/issues/128) - Fixed `onJsAlert`, `onJsConfirm`, `onJsPrompt` for `InAppBrowser` on Android +- Fixed `InAppBrowser.openWithSystemBrowser crash on iOS` [#358](https://github.com/pichillilorenzo/flutter_inappwebview/issues/358) ## 3.2.0 diff --git a/README.md b/README.md index 793a2ef3..5bc64d16 100755 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Donate to this project using Paypal](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.me/LorenzoPichilli) [![Donate to this project using Patreon](https://img.shields.io/badge/patreon-donate-yellow.svg)](https://www.patreon.com/bePatron?u=9269604) -A Flutter plugin that allows you to add an inline webview or open an in-app browser window. +A Flutter plugin that allows you to add an inline webview, to use an headless webview, and to open an in-app browser window. ### Requirements @@ -16,13 +16,32 @@ A Flutter plugin that allows you to add an inline webview or open an in-app brow - Android: `minSdkVersion 17` and add support for `androidx` (see [AndroidX Migration](https://flutter.dev/docs/development/androidx-migration) to migrate an existing app) - iOS: `--ios-language swift`, Xcode version `>= 11` +### IMPORTANT Note for Android and iOS + +If you're running an application and need to access the binary messenger before `runApp()` has been called +(for example, during plugin initialization), then you need to explicitly call the `WidgetsFlutterBinding.ensureInitialized()` first. + +An example: +```dart +void main() { + // it should be the first line in main method + WidgetsFlutterBinding.ensureInitialized(); + + // rest of your app code + runApp(MyApp()); +} +``` + ### IMPORTANT Note for Android -If you are starting a new fresh app, you need to create the Flutter App with `flutter create --androidx -i swift` to add support for `androidx`, otherwise it won't work (see [AndroidX Migration](https://flutter.dev/docs/development/androidx-migration) to migrate an existing app). +If you are starting a new fresh app, you need to create the Flutter App with `flutter create --androidx -i swift` +to add support for `androidx`, otherwise it won't work (see [AndroidX Migration](https://flutter.dev/docs/development/androidx-migration) to migrate an existing app). -During the build, if Android fails with `Error: uses-sdk:minSdkVersion 16 cannot be smaller than version 17 declared in library`, it means that you need to update the `minSdkVersion` of your `android/app/build.gradle` file to at least `17`. +During the build, if Android fails with `Error: uses-sdk:minSdkVersion 16 cannot be smaller than version 17 declared in library`, +it means that you need to update the `minSdkVersion` of your `android/app/build.gradle` file to at least `17`. -Also, you need to add `` in the `android/app/src/main/AndroidManifest.xml` file in order to give minimum permission to perform network operations in your application. +Also, you need to add `` in the `android/app/src/main/AndroidManifest.xml` +file in order to give minimum permission to perform network operations in your application. If you `flutter create`d your project prior to version `1.12`, you need to make sure to update your project in order to use the new **Java Embedding API**! Take a look at the official Flutter wiki: [Upgrading pre 1.12 Android projects](https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects). @@ -42,7 +61,8 @@ Also, note that to use the `InAppWebView` widget on Android, it requires **Andro ### IMPORTANT Note for iOS -If you are starting a new fresh app, you need to create the Flutter App with `flutter create --androidx -i swift` (see [flutter/flutter#13422 (comment)](https://github.com/flutter/flutter/issues/13422#issuecomment-392133780)), otherwise, you will get this message: +If you are starting a new fresh app, you need to create the Flutter App with `flutter create --androidx -i swift` +(see [flutter/flutter#13422 (comment)](https://github.com/flutter/flutter/issues/13422#issuecomment-392133780)), otherwise, you will get this message: ``` === BUILD TARGET flutter_inappwebview OF PROJECT Pods WITH CONFIGURATION Debug === The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift. Supported values are: 3.0, 4.0, 4.2, 5.0. This setting can be set in the build settings editor. diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index 1152d456..d8ce85ed 100755 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"e2e","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/e2e-0.2.4+4/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]}],"android":[{"name":"e2e","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/e2e-0.2.4+4/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"e2e","dependencies":[]},{"name":"flutter_inappwebview","dependencies":[]}],"date_created":"2020-05-23 00:16:16.872956","version":"1.17.1"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"e2e","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/e2e-0.2.4+4/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]}],"android":[{"name":"e2e","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/e2e-0.2.4+4/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"e2e","dependencies":[]},{"name":"flutter_inappwebview","dependencies":[]}],"date_created":"2020-05-23 12:13:45.779062","version":"1.17.1"} \ No newline at end of file diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index b5a5f445..4fa3085f 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -255,20 +255,14 @@ inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", "${PODS_ROOT}/../Flutter/Flutter.framework", - "${BUILT_PRODUCTS_DIR}/Reachability/Reachability.framework", - "${BUILT_PRODUCTS_DIR}/connectivity/connectivity.framework", - "${BUILT_PRODUCTS_DIR}/flutter_downloader/flutter_downloader.framework", + "${BUILT_PRODUCTS_DIR}/e2e/e2e.framework", "${BUILT_PRODUCTS_DIR}/flutter_inappwebview/flutter_inappwebview.framework", - "${BUILT_PRODUCTS_DIR}/path_provider/path_provider.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/connectivity.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_downloader.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/e2e.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_inappwebview.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/path_provider.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; diff --git a/example/lib/in_app_browser_example.screen.dart b/example/lib/in_app_browser_example.screen.dart index 8cfc06b6..53f64556 100755 --- a/example/lib/in_app_browser_example.screen.dart +++ b/example/lib/in_app_browser_example.screen.dart @@ -37,7 +37,8 @@ class MyInAppBrowser extends InAppBrowser { } @override - Future shouldOverrideUrlLoading(ShouldOverrideUrlLoadingRequest shouldOverrideUrlLoadingRequest) async { + Future shouldOverrideUrlLoading( + ShouldOverrideUrlLoadingRequest shouldOverrideUrlLoadingRequest) async { print("\n\nOverride ${shouldOverrideUrlLoadingRequest.url}\n\n"); return ShouldOverrideUrlLoadingAction.ALLOW; } @@ -85,19 +86,29 @@ class _InAppBrowserExampleScreenState extends State { )), drawer: myDrawer(context: context), body: Center( - child: RaisedButton( - onPressed: () async { - await widget.browser.openFile( - assetFilePath: "assets/index.html", - options: InAppBrowserClassOptions( - inAppWebViewGroupOptions: InAppWebViewGroupOptions( - crossPlatform: InAppWebViewOptions( - debuggingEnabled: true, - useShouldOverrideUrlLoading: true, - useOnLoadResource: true, - )))); - }, - child: Text("Open Webview Browser")), - )); + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + RaisedButton( + onPressed: () async { + await widget.browser.openFile( + assetFilePath: "assets/index.html", + options: InAppBrowserClassOptions( + inAppWebViewGroupOptions: InAppWebViewGroupOptions( + crossPlatform: InAppWebViewOptions( + debuggingEnabled: true, + useShouldOverrideUrlLoading: true, + useOnLoadResource: true, + )))); + }, + child: Text("Open Webview Browser")), + Container(height: 40), + RaisedButton( + onPressed: () async { + await InAppBrowser.openWithSystemBrowser( + url: "https://flutter.dev/"); + }, + child: Text("Open System Browser")), + ]))); } } diff --git a/ios/Classes/InAppBrowserManager.swift b/ios/Classes/InAppBrowserManager.swift index fd110918..77fd11a6 100755 --- a/ios/Classes/InAppBrowserManager.swift +++ b/ios/Classes/InAppBrowserManager.swift @@ -34,10 +34,10 @@ public class InAppBrowserManager: NSObject, FlutterPlugin { public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { let arguments = call.arguments as? NSDictionary - let uuid: String = arguments!["uuid"] as! String switch call.method { case "openUrl": + let uuid = arguments!["uuid"] as! String let url = arguments!["url"] as! String let options = arguments!["options"] as! [String: Any?] let headers = arguments!["headers"] as! [String: String] @@ -46,6 +46,7 @@ public class InAppBrowserManager: NSObject, FlutterPlugin { result(true) break case "openFile": + let uuid = arguments!["uuid"] as! String var url = arguments!["url"] as! String let key = InAppBrowserManager.registrar!.lookupKey(forAsset: url) let assetURL = Bundle.main.url(forResource: key, withExtension: nil) @@ -62,6 +63,7 @@ public class InAppBrowserManager: NSObject, FlutterPlugin { result(true) break case "openData": + let uuid = arguments!["uuid"] as! String let options = arguments!["options"] as! [String: Any?] let data = arguments!["data"] as! String let mimeType = arguments!["mimeType"] as! String diff --git a/pubspec.yaml b/pubspec.yaml index 07e2c70d..32c4a798 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: flutter_inappwebview -description: A Flutter plugin that allows you to add an inline webview or open an in-app browser window. +description: A Flutter plugin that allows you to add an inline webview, to use an headless webview, and to open an in-app browser window. version: 3.3.0 homepage: https://github.com/pichillilorenzo/flutter_inappwebview