mirror of
https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background
synced 2024-11-14 19:44:53 +00:00
Fix app freeze on iOS using wkwebview-engine
This commit is contained in:
parent
2801364ed8
commit
b7a911a974
@ -1,4 +1,8 @@
|
|||||||
## ChangeLog
|
## 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)
|
#### Version 0.7.1 (30.01.2017)
|
||||||
- Bug fixes for iOS9 and Android
|
- Bug fixes for iOS9 and Android
|
||||||
- Allow app to be excluded from recent list on Android
|
- Allow app to be excluded from recent list on Android
|
||||||
|
@ -43,8 +43,6 @@ Or install from local source:
|
|||||||
|
|
||||||
$ cordova plugin add cordova-plugin-background-mode --searchpath <path>
|
$ 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
|
## Usage
|
||||||
The plugin creates the object `cordova.plugins.backgroundMode` and is accessible after the *deviceready* event has been fired.
|
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);
|
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
|
### Check if running in background
|
||||||
Once the plugin has been enabled and the app has entered the background, the background mode becomes active.
|
Once the plugin has been enabled and the app has entered the background, the background mode becomes active.
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ NSString* const kAPPBackgroundEventDeactivate = @"deactivate";
|
|||||||
*/
|
*/
|
||||||
- (void) pluginInitialize
|
- (void) pluginInitialize
|
||||||
{
|
{
|
||||||
enabled = [self.class isRunningWebKit];
|
enabled = NO;
|
||||||
[self configureAudioPlayer];
|
[self configureAudioPlayer];
|
||||||
[self configureAudioSession];
|
[self configureAudioSession];
|
||||||
[self observeLifeCycle];
|
[self observeLifeCycle];
|
||||||
@ -74,9 +74,6 @@ NSString* const kAPPBackgroundEventDeactivate = @"deactivate";
|
|||||||
name:UIApplicationWillEnterForegroundNotification
|
name:UIApplicationWillEnterForegroundNotification
|
||||||
object:nil];
|
object:nil];
|
||||||
|
|
||||||
if ([self.class isRunningWebKit])
|
|
||||||
return;
|
|
||||||
|
|
||||||
[listener addObserver:self
|
[listener addObserver:self
|
||||||
selector:@selector(handleAudioSessionInterruption:)
|
selector:@selector(handleAudioSessionInterruption:)
|
||||||
name:AVAudioSessionInterruptionNotification
|
name:AVAudioSessionInterruptionNotification
|
||||||
@ -105,7 +102,7 @@ NSString* const kAPPBackgroundEventDeactivate = @"deactivate";
|
|||||||
*/
|
*/
|
||||||
- (void) disable:(CDVInvokedUrlCommand*)command
|
- (void) disable:(CDVInvokedUrlCommand*)command
|
||||||
{
|
{
|
||||||
if (!enabled || [self.class isRunningWebKit])
|
if (!enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
enabled = NO;
|
enabled = NO;
|
||||||
@ -124,10 +121,7 @@ NSString* const kAPPBackgroundEventDeactivate = @"deactivate";
|
|||||||
if (!enabled)
|
if (!enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (![self.class isRunningWebKit]) {
|
[audioPlayer play];
|
||||||
[audioPlayer play];
|
|
||||||
}
|
|
||||||
|
|
||||||
[self fireEvent:kAPPBackgroundEventActivate];
|
[self fireEvent:kAPPBackgroundEventActivate];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +134,7 @@ NSString* const kAPPBackgroundEventDeactivate = @"deactivate";
|
|||||||
NSLog(@"BackgroundMode: On simulator apps never pause in background!");
|
NSLog(@"BackgroundMode: On simulator apps never pause in background!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (audioPlayer.isPlaying || [self.class isRunningWebKit]) {
|
if (audioPlayer.isPlaying) {
|
||||||
[self fireEvent:kAPPBackgroundEventDeactivate];
|
[self fireEvent:kAPPBackgroundEventDeactivate];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,9 +167,6 @@ NSString* const kAPPBackgroundEventDeactivate = @"deactivate";
|
|||||||
AVAudioSession* session = [AVAudioSession
|
AVAudioSession* session = [AVAudioSession
|
||||||
sharedInstance];
|
sharedInstance];
|
||||||
|
|
||||||
if ([self.class isRunningWebKit])
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Don't activate the audio session yet
|
// Don't activate the audio session yet
|
||||||
[session setActive:NO error:NULL];
|
[session setActive:NO error:NULL];
|
||||||
|
|
||||||
@ -275,6 +266,9 @@ NSString* const kAPPBackgroundEventDeactivate = @"deactivate";
|
|||||||
[obj setValue:[NSNumber numberWithBool:YES]
|
[obj setValue:[NSNumber numberWithBool:YES]
|
||||||
forKey:[APPBackgroundMode wkProperty]];
|
forKey:[APPBackgroundMode wkProperty]];
|
||||||
|
|
||||||
|
[obj setValue:[NSNumber numberWithBool:NO]
|
||||||
|
forKey:@"_requiresUserActionForMediaPlayback"];
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
SwizzleSelectorWithBlock_End;
|
SwizzleSelectorWithBlock_End;
|
||||||
|
@ -341,8 +341,9 @@ exports.pluginInitialize = function () {
|
|||||||
this._isAndroid = device.platform.match(/^android|amazon/i) !== null;
|
this._isAndroid = device.platform.match(/^android|amazon/i) !== null;
|
||||||
this.setDefaults({});
|
this.setDefaults({});
|
||||||
|
|
||||||
if (device.platform == 'browser' || window.webkit !== undefined) {
|
if (device.platform == 'browser') {
|
||||||
this.enable();
|
this.enable();
|
||||||
|
this._isEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._isActive = this._isActive || device.platform == 'browser';
|
this._isActive = this._isActive || device.platform == 'browser';
|
||||||
|
Loading…
Reference in New Issue
Block a user