Fix app freeze on iOS using wkwebview-engine

This commit is contained in:
Sebastián Katzer 2017-02-02 15:22:12 +01:00
parent 2801364ed8
commit b7a911a974
4 changed files with 13 additions and 18 deletions

View File

@ -1,4 +1,8 @@
## ChangeLog
#### Version 0.7.2 (02.02.2017)
- Fixed app freeze on iOS using wkwebview-engine
- Websocket sample in SampleApp
#### Version 0.7.1 (30.01.2017)
- Bug fixes for iOS9 and Android
- Allow app to be excluded from recent list on Android

View File

@ -43,8 +43,6 @@ Or install from local source:
$ cordova plugin add cordova-plugin-background-mode --searchpath <path>
__Note:__ In combination with the `cordova-plugin-wkwebview-engine` plugin the UIBackgroundModes section added by the plugin inside the *-Info.plist can be removed. That might increase the chance to submit the app to the app store.
## Usage
The plugin creates the object `cordova.plugins.backgroundMode` and is accessible after the *deviceready* event has been fired.
@ -71,8 +69,6 @@ cordova.plugins.backgroundMode.disable();
cordova.plugins.backgroundMode.setEnabled(false);
```
__Note:__ By using `wkwebview-engine` on iOS, the plugin is enabled by default and cannot be disabled.
### Check if running in background
Once the plugin has been enabled and the app has entered the background, the background mode becomes active.

View File

@ -50,7 +50,7 @@ NSString* const kAPPBackgroundEventDeactivate = @"deactivate";
*/
- (void) pluginInitialize
{
enabled = [self.class isRunningWebKit];
enabled = NO;
[self configureAudioPlayer];
[self configureAudioSession];
[self observeLifeCycle];
@ -74,9 +74,6 @@ NSString* const kAPPBackgroundEventDeactivate = @"deactivate";
name:UIApplicationWillEnterForegroundNotification
object:nil];
if ([self.class isRunningWebKit])
return;
[listener addObserver:self
selector:@selector(handleAudioSessionInterruption:)
name:AVAudioSessionInterruptionNotification
@ -105,7 +102,7 @@ NSString* const kAPPBackgroundEventDeactivate = @"deactivate";
*/
- (void) disable:(CDVInvokedUrlCommand*)command
{
if (!enabled || [self.class isRunningWebKit])
if (!enabled)
return;
enabled = NO;
@ -124,10 +121,7 @@ NSString* const kAPPBackgroundEventDeactivate = @"deactivate";
if (!enabled)
return;
if (![self.class isRunningWebKit]) {
[audioPlayer play];
}
[audioPlayer play];
[self fireEvent:kAPPBackgroundEventActivate];
}
@ -140,7 +134,7 @@ NSString* const kAPPBackgroundEventDeactivate = @"deactivate";
NSLog(@"BackgroundMode: On simulator apps never pause in background!");
}
if (audioPlayer.isPlaying || [self.class isRunningWebKit]) {
if (audioPlayer.isPlaying) {
[self fireEvent:kAPPBackgroundEventDeactivate];
}
@ -173,9 +167,6 @@ NSString* const kAPPBackgroundEventDeactivate = @"deactivate";
AVAudioSession* session = [AVAudioSession
sharedInstance];
if ([self.class isRunningWebKit])
return;
// Don't activate the audio session yet
[session setActive:NO error:NULL];
@ -275,6 +266,9 @@ NSString* const kAPPBackgroundEventDeactivate = @"deactivate";
[obj setValue:[NSNumber numberWithBool:YES]
forKey:[APPBackgroundMode wkProperty]];
[obj setValue:[NSNumber numberWithBool:NO]
forKey:@"_requiresUserActionForMediaPlayback"];
return obj;
}
SwizzleSelectorWithBlock_End;

View File

@ -341,8 +341,9 @@ exports.pluginInitialize = function () {
this._isAndroid = device.platform.match(/^android|amazon/i) !== null;
this.setDefaults({});
if (device.platform == 'browser' || window.webkit !== undefined) {
if (device.platform == 'browser') {
this.enable();
this._isEnabled = true;
}
this._isActive = this._isActive || device.platform == 'browser';