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

User Agent in ipad not detected #899

Open stephanievea opened 3 years ago

stephanievea commented 3 years ago

WebviewScaffold( primary: false, resizeToAvoidBottomInset: !Platform.isIOS, userAgent: "SomeRandomUserAgent", url: "$someUrl", appBar: ab, initialChild: Container(), withLocalStorage: true, withJavascript: true, );

We have tested this in iphone ipad android simulators and devices and it works on iphone and android 
but not in ipad. 

what appears - in ipad - according to our logs is 
"Mozilla/5.9 (Mackintosh; Intel Mac OS X 10_15_4) AppleWebKit/605/1/15 (KHTML, like Gecko)"

Otherwise it "SomeRandomUserAgent"
ouija commented 3 years ago

There is a fix described here:

In your project folder, edit the ./ios/.symlinks/plugins/flutter_webview_plugin/ios/Classes/FlutterWebviewPlugin.m file and after line 144 insert the following:

if (@available(iOS 9.0, *)) {
    if (userAgent != (id)[NSNull null]) {
        self.webview.customUserAgent = userAgent;
    }
}

Then do a flutter clean/pub get and it should resolve the issue.