Skip to content

Commit 46c080f

Browse files
NiklasMerztimbru31
andauthored
(ios): allow to set "preferredContentMode" (apache#688)
PreferredContentMode can now be set with preference config. Since iPadOS came out iPads get a desktop Safari useragent by default. see apache#687 Co-authored-by: Tim Brust <[email protected]>
1 parent 2a1c0c0 commit 46c080f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,16 @@ At the moment the only supported target in OSX is `_system`.
176176

177177
`_blank` and `_self` targets are not yet implemented and are ignored silently. Pull requests and patches to get these to work are greatly appreciated.
178178

179+
### iOS Quirks
180+
181+
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. You can change this with the `PreferredContentMode` preference in `config.xml`.
182+
183+
```xml
184+
<preference name="PreferredContentMode" value="mobile" />
185+
```
186+
187+
The example above forces the user agent to contain `iPad`. The other option is to use the value `desktop` to turn the user agent to `Macintosh`.
188+
179189
### Browser Quirks
180190

181191
- Plugin is implemented via iframe,

src/ios/CDVWKInAppBrowser.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,15 @@ - (void)createViews
757757
configuration.mediaPlaybackRequiresUserAction = _browserOptions.mediaplaybackrequiresuseraction;
758758
}
759759

760+
if (@available(iOS 13.0, *)) {
761+
NSString *contentMode = [self settingForKey:@"PreferredContentMode"];
762+
if ([contentMode isEqual: @"mobile"]) {
763+
configuration.defaultWebpagePreferences.preferredContentMode = WKContentModeMobile;
764+
} else if ([contentMode isEqual: @"desktop"]) {
765+
configuration.defaultWebpagePreferences.preferredContentMode = WKContentModeDesktop;
766+
}
767+
768+
}
760769

761770

762771
self.webView = [[WKWebView alloc] initWithFrame:webViewBounds configuration:configuration];

0 commit comments

Comments
 (0)