Skip to content

Commit

Permalink
feat(ios): Add WKSuspendInBackground preference (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Apr 22, 2019
1 parent c61e4d5 commit 3613602
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<allow-navigation href="httpsionic://*"/>` if `iosScheme` is set to `httpsionic`).

#### WKSuspendInBackground

```xml
<preference name="WKSuspendInBackground" value="false" />
```

Default value is `true` (suspend).

Set to false to stop WKWebView suspending in background too eagerly.

#### KeyboardAppearanceDark

```xml
Expand Down
19 changes: 19 additions & 0 deletions src/ios/CDVWKWebViewEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 3613602

Please sign in to comment.