Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/ios/CDVWKWebViewEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ @interface CDVWKWebViewEngine ()

@end

// expose private configuration value required for background operation
@interface WKWebViewConfiguration ()

@property (setter=_setAlwaysRunsAtForegroundPriority:, nonatomic) bool _alwaysRunsAtForegroundPriority;

@end

// see forwardingTargetForSelector: selector comment for the reason for this pragma
#pragma clang diagnostic ignored "-Wprotocol"

Expand All @@ -122,6 +129,9 @@ - (instancetype)initWithFrame:(CGRect)frame
if(!IsAtLeastiOSVersion(@"9.0")) {
return nil;
}
// add to keyWindow to ensure it is 'active'
[UIApplication.sharedApplication.keyWindow addSubview:self.engineWebView];

self.frame = frame;
[GCDWebServer setLogLevel: kGCDWebServerLoggingLevel_Warning];
self.webServer = [[GCDWebServer alloc] init];
Expand Down Expand Up @@ -154,6 +164,8 @@ - (WKWebViewConfiguration*) createConfigurationFromSettings:(NSDictionary*)setti
if (settings == nil) {
return configuration;
}
//required to stop wkwebview suspending in background too eagerly (as used in background mode plugin)
configuration._alwaysRunsAtForegroundPriority = [settings cordovaBoolSettingForKey:@"WKEnableBackground" defaultValue:NO];
configuration.allowsInlineMediaPlayback = [settings cordovaBoolSettingForKey:@"AllowInlineMediaPlayback" defaultValue:YES];
configuration.suppressesIncrementalRendering = [settings cordovaBoolSettingForKey:@"SuppressesIncrementalRendering" defaultValue:NO];
configuration.allowsAirPlayForMediaPlayback = [settings cordovaBoolSettingForKey:@"MediaPlaybackAllowsAirPlay" defaultValue:YES];
Expand Down Expand Up @@ -205,6 +217,8 @@ - (void)pluginInitialize
configuration.userContentController = userContentController;

// re-create WKWebView, since we need to update configuration
// remove from keyWindow before recreating
[self.engineWebView removeFromSuperview];
WKWebView* wkWebView = [[WKWebView alloc] initWithFrame:self.frame configuration:configuration];

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
Expand All @@ -216,6 +230,9 @@ - (void)pluginInitialize
wkWebView.UIDelegate = self.uiDelegate;
self.engineWebView = wkWebView;

// add to keyWindow to ensure it is 'active'
[UIApplication.sharedApplication.keyWindow addSubview:self.engineWebView];

if (IsAtLeastiOSVersion(@"9.0") && [self.viewController isKindOfClass:[CDVViewController class]]) {
wkWebView.customUserAgent = ((CDVViewController*) self.viewController).userAgent;
}
Expand Down