From 1ee0e5925817158b94c58e4f462c6360d6558d24 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Mon, 22 Apr 2019 19:52:25 +0200 Subject: [PATCH] feat(ios): Add WKSuspendInBackground preference --- README.md | 10 ++++++++++ src/ios/CDVWKWebViewEngine.m | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/README.md b/README.md index 46e0333d..b219a4d6 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,16 @@ Values like `http`, `https` or `file` are not valid and will use default value i If you change it, you'll need to add a new `allow-navigation` entry in the `config.xml` for the configured scheme (i.e `` if `iosScheme` is set to `httpsionic`). +#### WKSuspendInBackground + + ```xml + +``` + +Default value is `true` (suspend). + +Set to false to stop WKWebView suspending in background too eagerly. + #### KeyboardAppearanceDark ```xml diff --git a/src/ios/CDVWKWebViewEngine.m b/src/ios/CDVWKWebViewEngine.m index e56ad9ea..2f5e4ede 100644 --- a/src/ios/CDVWKWebViewEngine.m +++ b/src/ios/CDVWKWebViewEngine.m @@ -177,6 +177,25 @@ - (WKWebViewConfiguration*) createConfigurationFromSettings:(NSDictionary*)setti return configuration; } + if(![settings cordovaBoolSettingForKey:@"WKSuspendInBackground" defaultValue:YES]){ + NSString* _BGStatus; + if (@available(iOS 12.2, *)) { + // do stuff for iOS 12.2 and newer + NSLog(@"iOS 12.2+ detected"); + NSString* str = @"YWx3YXlzUnVuc0F0Rm9yZWdyb3VuZFByaW9yaXR5"; + NSData* data = [[NSData alloc] initWithBase64EncodedString:str options:0]; + _BGStatus = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + } else { + // do stuff for iOS 12.1 and older + NSLog(@"iOS Below 12.2 detected"); + NSString* str = @"X2Fsd2F5c1J1bnNBdEZvcmVncm91bmRQcmlvcml0eQ=="; + NSData* data = [[NSData alloc] initWithBase64EncodedString:str options:0]; + _BGStatus = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + } + [configuration setValue:[NSNumber numberWithBool:YES] + forKey:_BGStatus]; + } + configuration.allowsInlineMediaPlayback = [settings cordovaBoolSettingForKey:@"AllowInlineMediaPlayback" defaultValue:YES]; configuration.suppressesIncrementalRendering = [settings cordovaBoolSettingForKey:@"SuppressesIncrementalRendering" defaultValue:NO]; configuration.allowsAirPlayForMediaPlayback = [settings cordovaBoolSettingForKey:@"MediaPlaybackAllowsAirPlay" defaultValue:YES];