fluttercommunity / flutter_webview_plugin

Community WebView Plugin - Allows Flutter to communicate with a native WebView.
https://pub.dev/packages/flutter_webview_plugin
Other
1.48k stars 929 forks source link

[iOS] Not working when rootViewController is not FlutterViewController #866

Open foxsofter opened 3 years ago

foxsofter commented 3 years ago

System info

Issue occurs on: both Plugin version: all Flutter doctor output: x

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
    channel = [FlutterMethodChannel
               methodChannelWithName:CHANNEL_NAME
               binaryMessenger:[registrar messenger]];

    UIViewController *viewController = [UIApplication sharedApplication].delegate.window.rootViewController;
    FlutterWebviewPlugin* instance = [[FlutterWebviewPlugin alloc] initWithViewController:viewController];

    [registrar addMethodCallDelegate:instance channel:channel];
}
foxsofter commented 3 years ago

Getting it from the engine when needed is the right solution,because the ViewController of FlutterEngine may change at any time. here