Skip to content

Commit b7a911a

Browse files
committed
Fix app freeze on iOS using wkwebview-engine
1 parent 2801364 commit b7a911a

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
## ChangeLog
2+
#### Version 0.7.2 (02.02.2017)
3+
- Fixed app freeze on iOS using wkwebview-engine
4+
- Websocket sample in SampleApp
5+
26
#### Version 0.7.1 (30.01.2017)
37
- Bug fixes for iOS9 and Android
48
- Allow app to be excluded from recent list on Android

README.md

-4
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ Or install from local source:
4343

4444
$ cordova plugin add cordova-plugin-background-mode --searchpath <path>
4545

46-
__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.
47-
4846

4947
## Usage
5048
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();
7169
cordova.plugins.backgroundMode.setEnabled(false);
7270
```
7371

74-
__Note:__ By using `wkwebview-engine` on iOS, the plugin is enabled by default and cannot be disabled.
75-
7672
### Check if running in background
7773
Once the plugin has been enabled and the app has entered the background, the background mode becomes active.
7874

src/ios/APPBackgroundMode.m

+7-13
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ + (void) load
5050
*/
5151
- (void) pluginInitialize
5252
{
53-
enabled = [self.class isRunningWebKit];
53+
enabled = NO;
5454
[self configureAudioPlayer];
5555
[self configureAudioSession];
5656
[self observeLifeCycle];
@@ -74,9 +74,6 @@ - (void) observeLifeCycle
7474
name:UIApplicationWillEnterForegroundNotification
7575
object:nil];
7676

77-
if ([self.class isRunningWebKit])
78-
return;
79-
8077
[listener addObserver:self
8178
selector:@selector(handleAudioSessionInterruption:)
8279
name:AVAudioSessionInterruptionNotification
@@ -105,7 +102,7 @@ - (void) enable:(CDVInvokedUrlCommand*)command
105102
*/
106103
- (void) disable:(CDVInvokedUrlCommand*)command
107104
{
108-
if (!enabled || [self.class isRunningWebKit])
105+
if (!enabled)
109106
return;
110107

111108
enabled = NO;
@@ -124,10 +121,7 @@ - (void) keepAwake
124121
if (!enabled)
125122
return;
126123

127-
if (![self.class isRunningWebKit]) {
128-
[audioPlayer play];
129-
}
130-
124+
[audioPlayer play];
131125
[self fireEvent:kAPPBackgroundEventActivate];
132126
}
133127

@@ -140,7 +134,7 @@ - (void) stopKeepingAwake
140134
NSLog(@"BackgroundMode: On simulator apps never pause in background!");
141135
}
142136

143-
if (audioPlayer.isPlaying || [self.class isRunningWebKit]) {
137+
if (audioPlayer.isPlaying) {
144138
[self fireEvent:kAPPBackgroundEventDeactivate];
145139
}
146140

@@ -173,9 +167,6 @@ - (void) configureAudioSession
173167
AVAudioSession* session = [AVAudioSession
174168
sharedInstance];
175169

176-
if ([self.class isRunningWebKit])
177-
return;
178-
179170
// Don't activate the audio session yet
180171
[session setActive:NO error:NULL];
181172

@@ -275,6 +266,9 @@ + (void) swizzleWKWebViewEngine
275266
[obj setValue:[NSNumber numberWithBool:YES]
276267
forKey:[APPBackgroundMode wkProperty]];
277268

269+
[obj setValue:[NSNumber numberWithBool:NO]
270+
forKey:@"_requiresUserActionForMediaPlayback"];
271+
278272
return obj;
279273
}
280274
SwizzleSelectorWithBlock_End;

www/background-mode.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,9 @@ exports.pluginInitialize = function () {
341341
this._isAndroid = device.platform.match(/^android|amazon/i) !== null;
342342
this.setDefaults({});
343343

344-
if (device.platform == 'browser' || window.webkit !== undefined) {
344+
if (device.platform == 'browser') {
345345
this.enable();
346+
this._isEnabled = true;
346347
}
347348

348349
this._isActive = this._isActive || device.platform == 'browser';

0 commit comments

Comments
 (0)