From a8f2af6ad0cbf1715449a9717a8ef3028f7ddade Mon Sep 17 00:00:00 2001 From: Anton Kalmykov Date: Thu, 17 Sep 2020 13:38:15 +0500 Subject: [PATCH] add PreferredContentMode setting for iOS --- README.md | 10 ++++++++++ src/ios/CDVWKWebViewEngine.m | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/README.md b/README.md index 70c4884f..c3b844db 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,16 @@ Whether to use a dark styled keyboard on iOS Ionic apps work better if the WKWebView is not scrollable, so the scroll is disabled by default, but can be enabled with this preference. This only affects the main ScrollView of the WKWebView, so only affects the body, not other scrollable components. +#### PreferredContentMode + +```xml + +``` + +Override the default content mode (and user agent) for the WKWebView on iPads (`iPadOS 13.0+`). Valid values are: `mobile` and `desktop`. + +Since the introduction of iPadOS 13, iPads try to adapt their content mode / user agent for the optimal browsing experience. This may result in iPads having their user agent set to Macintosh making it hard to detect them as mobile devices using user agent string sniffing. + ## Plugin Requirements * **Cordova CLI**: 7.1.0+ diff --git a/src/ios/CDVWKWebViewEngine.m b/src/ios/CDVWKWebViewEngine.m index d6b24084..733b3a8c 100644 --- a/src/ios/CDVWKWebViewEngine.m +++ b/src/ios/CDVWKWebViewEngine.m @@ -204,6 +204,16 @@ - (WKWebViewConfiguration*) createConfigurationFromSettings:(NSDictionary*)setti configuration.allowsInlineMediaPlayback = [settings cordovaBoolSettingForKey:@"AllowInlineMediaPlayback" defaultValue:YES]; configuration.suppressesIncrementalRendering = [settings cordovaBoolSettingForKey:@"SuppressesIncrementalRendering" defaultValue:NO]; configuration.allowsAirPlayForMediaPlayback = [settings cordovaBoolSettingForKey:@"MediaPlaybackAllowsAirPlay" defaultValue:YES]; + + if (@available(iOS 13.0, *)) { + NSString *contentMode = [settings cordovaSettingForKey:@"PreferredContentMode"]; + if ([contentMode isEqual: @"mobile"]) { + configuration.defaultWebpagePreferences.preferredContentMode = WKContentModeMobile; + } else if ([contentMode isEqual: @"desktop"]) { + configuration.defaultWebpagePreferences.preferredContentMode = WKContentModeDesktop; + } + } + return configuration; }