Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3613602

Browse files
authoredApr 22, 2019
feat(ios): Add WKSuspendInBackground preference (#356)
1 parent c61e4d5 commit 3613602

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
 

‎README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ Values like `http`, `https` or `file` are not valid and will use default value i
107107

108108
If you change it, you'll need to add a new `allow-navigation` entry in the `config.xml` for the configured scheme (i.e `<allow-navigation href="httpsionic://*"/>` if `iosScheme` is set to `httpsionic`).
109109

110+
#### WKSuspendInBackground
111+
112+
```xml
113+
<preference name="WKSuspendInBackground" value="false" />
114+
```
115+
116+
Default value is `true` (suspend).
117+
118+
Set to false to stop WKWebView suspending in background too eagerly.
119+
110120
#### KeyboardAppearanceDark
111121

112122
```xml

‎src/ios/CDVWKWebViewEngine.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,25 @@ - (WKWebViewConfiguration*) createConfigurationFromSettings:(NSDictionary*)setti
177177
return configuration;
178178
}
179179

180+
if(![settings cordovaBoolSettingForKey:@"WKSuspendInBackground" defaultValue:YES]){
181+
NSString* _BGStatus;
182+
if (@available(iOS 12.2, *)) {
183+
// do stuff for iOS 12.2 and newer
184+
NSLog(@"iOS 12.2+ detected");
185+
NSString* str = @"YWx3YXlzUnVuc0F0Rm9yZWdyb3VuZFByaW9yaXR5";
186+
NSData* data = [[NSData alloc] initWithBase64EncodedString:str options:0];
187+
_BGStatus = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
188+
} else {
189+
// do stuff for iOS 12.1 and older
190+
NSLog(@"iOS Below 12.2 detected");
191+
NSString* str = @"X2Fsd2F5c1J1bnNBdEZvcmVncm91bmRQcmlvcml0eQ==";
192+
NSData* data = [[NSData alloc] initWithBase64EncodedString:str options:0];
193+
_BGStatus = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
194+
}
195+
[configuration setValue:[NSNumber numberWithBool:YES]
196+
forKey:_BGStatus];
197+
}
198+
180199
configuration.allowsInlineMediaPlayback = [settings cordovaBoolSettingForKey:@"AllowInlineMediaPlayback" defaultValue:YES];
181200
configuration.suppressesIncrementalRendering = [settings cordovaBoolSettingForKey:@"SuppressesIncrementalRendering" defaultValue:NO];
182201
configuration.allowsAirPlayForMediaPlayback = [settings cordovaBoolSettingForKey:@"MediaPlaybackAllowsAirPlay" defaultValue:YES];

0 commit comments

Comments
 (0)
Please sign in to comment.