Skip to content

Commit 3b82c16

Browse files
dpa99cjanpio
authored andcommitted
Fix crashes when using WKWebView implementation on iOS 9. (#337)
Fixes #323. Fixes #324.
1 parent 978b147 commit 3b82c16

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ instance, or the system browser.
142142
- __toolbar__: set to `yes` or `no` to turn the toolbar on or off for the InAppBrowser (defaults to `yes`)
143143
- __toolbarcolor__: set as a valid hex color string, for example: `#00ff00`, to change from the default color of the toolbar. Only applicable if toolbar is not disabled.
144144
- __toolbartranslucent__: set to `yes` or `no` to make the toolbar translucent(semi-transparent) (defaults to `yes`). Only applicable if toolbar is not disabled.
145-
- __enableViewportScale__: Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`). Only applicable to UIWebView (`usewkwebview=no`).
146-
- __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`). Only applicable to UIWebView (`usewkwebview=no`).
147-
- __allowInlineMediaPlayback__: Set to `yes` or `no` to allow in-line HTML5 media playback, displaying within the browser window rather than a device-specific playback interface. The HTML's `video` element must also include the `webkit-playsinline` attribute (defaults to `no`) Only applicable to UIWebView (`usewkwebview=no`).
145+
- __enableViewportScale__: Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`). Only applicable to UIWebView (`usewkwebview=no`) and WKWebView (`usewkwebview=yes`) on iOS 10+.
146+
- __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`). Applicable to UIWebView (`usewkwebview=no`) and WKWebView (`usewkwebview=yes`).
147+
- __allowInlineMediaPlayback__: Set to `yes` or `no` to allow in-line HTML5 media playback, displaying within the browser window rather than a device-specific playback interface. The HTML's `video` element must also include the `webkit-playsinline` attribute (defaults to `no`). Applicable to UIWebView (`usewkwebview=no`) and WKWebView (`usewkwebview=yes`).
148148
- __keyboardDisplayRequiresUserAction__: Set to `yes` or `no` to open the keyboard when form elements receive focus via JavaScript's `focus()` call (defaults to `yes`). Only applicable to UIWebView (`usewkwebview=no`).
149149
- __suppressesIncrementalRendering__: Set to `yes` or `no` to wait until all new view content is received before being rendered (defaults to `no`). Only applicable to UIWebView (`usewkwebview=no`).
150150
- __presentationstyle__: Set to `pagesheet`, `formsheet` or `fullscreen` to set the [presentation style](http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalPresentationStyle) (defaults to `fullscreen`).

src/ios/CDVWKInAppBrowser.m

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -651,14 +651,20 @@ - (void)createViews
651651
[configuration.userContentController addScriptMessageHandler:self name:IAB_BRIDGE_NAME];
652652

653653
//WKWebView options
654-
configuration.ignoresViewportScaleLimits = _browserOptions.enableviewportscale;
655654
configuration.allowsInlineMediaPlayback = _browserOptions.allowinlinemediaplayback;
656-
if(_browserOptions.mediaplaybackrequiresuseraction == YES){
657-
configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAll;
658-
}else{
659-
configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
655+
if (IsAtLeastiOSVersion(@"10.0")) {
656+
configuration.ignoresViewportScaleLimits = _browserOptions.enableviewportscale;
657+
if(_browserOptions.mediaplaybackrequiresuseraction == YES){
658+
configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAll;
659+
}else{
660+
configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
661+
}
662+
}else{ // iOS 9
663+
configuration.mediaPlaybackRequiresUserAction = _browserOptions.mediaplaybackrequiresuseraction;
660664
}
661665

666+
667+
662668
self.webView = [[WKWebView alloc] initWithFrame:webViewBounds configuration:configuration];
663669

664670
[self.view addSubview:self.webView];

0 commit comments

Comments
 (0)