Hintergrundmodus kann gesondert aktiviert bzw. deaktiviert werden
This commit is contained in:
parent
68fa900cfb
commit
20cc5084f4
@ -11,7 +11,9 @@
|
||||
#import <Cordova/CDVPlugin.h>
|
||||
#import <CoreLocation/CoreLocation.h>
|
||||
|
||||
@interface APPBackgroundMode : CDVPlugin
|
||||
@interface APPBackgroundMode : CDVPlugin {
|
||||
BOOL _activated;
|
||||
}
|
||||
|
||||
// Aktiviert den Hintergrundmodus
|
||||
- (void) activate:(CDVInvokedUrlCommand *)command;
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
@interface APPBackgroundMode (PrivateMethods)
|
||||
|
||||
// Registriert die Listener für die (sleep/resume) Events
|
||||
- (void) observeLifeCycle:(CDVInvokedUrlCommand *)command;
|
||||
// Aktiviert den Hintergrundmodus
|
||||
- (void) activateMode;
|
||||
// Deaktiviert den Hintergrundmodus
|
||||
@ -22,6 +24,16 @@
|
||||
|
||||
@synthesize locationManager;
|
||||
|
||||
/**
|
||||
* @js-interface
|
||||
*
|
||||
* Registriert die Listener für die (sleep/resume) Events.
|
||||
*/
|
||||
- (void) observeLifeCycle:(CDVInvokedUrlCommand *)command
|
||||
{
|
||||
// Methode pluginInitialize wird aufgerufen, falls Instanz erstellt wurde
|
||||
}
|
||||
|
||||
/**
|
||||
* @js-interface
|
||||
*
|
||||
@ -49,6 +61,43 @@
|
||||
*/
|
||||
- (void) activateMode
|
||||
{
|
||||
_activated = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @obj-c-interface
|
||||
*
|
||||
* Deaktiviert den Hintergrundmodus.
|
||||
*/
|
||||
- (void) deactivateMode
|
||||
{
|
||||
_activated = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registriert die Listener für die (sleep/resume) Events und startet bzw. stoppt die Geo-Lokalisierung.
|
||||
*/
|
||||
- (void) pluginInitialize
|
||||
{
|
||||
[self activateMode];
|
||||
|
||||
if (&UIApplicationDidEnterBackgroundNotification && &UIApplicationWillEnterForegroundNotification) {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startUpdatingLocation) name:UIApplicationDidEnterBackgroundNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopUpdatingLocation) name:UIApplicationWillEnterForegroundNotification object:nil];
|
||||
} else {
|
||||
[self startUpdatingLocation];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Startet das Aktualisieren des Standpunktes.
|
||||
*/
|
||||
- (void) startUpdatingLocation
|
||||
{
|
||||
if (_activated == false) {
|
||||
return;
|
||||
};
|
||||
|
||||
if (!locationManager) {
|
||||
locationManager = [[CLLocationManager alloc] init];
|
||||
};
|
||||
@ -64,28 +113,14 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* @obj-c-interface
|
||||
*
|
||||
* Deaktiviert den Hintergrundmodus.
|
||||
* Beendet das Aktualisieren des Standpunktes.
|
||||
*/
|
||||
- (void) deactivateMode
|
||||
- (void) stopUpdatingLocation
|
||||
{
|
||||
if (locationManager) {
|
||||
// Beendet das Aktualisieren des Standpunktes
|
||||
[locationManager stopUpdatingLocation];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Registriert die Listener für die (sleep/resume) Events und startet bzw. stoppt die Geo-Lokalisierung.
|
||||
*/
|
||||
- (void) pluginInitialize
|
||||
{
|
||||
if (&UIApplicationDidEnterBackgroundNotification && &UIApplicationWillEnterForegroundNotification) {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(activateMode) name:UIApplicationDidEnterBackgroundNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deactivateMode) name:UIApplicationWillEnterForegroundNotification object:nil];
|
||||
} else {
|
||||
[self activateMode];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
@ -8,11 +8,14 @@
|
||||
*/
|
||||
|
||||
var BackgroundMode = function () {
|
||||
|
||||
// Registriert die Listener für die (sleep/resume) Events
|
||||
cordova.exec(null, null, 'BackgroundMode', 'observeLifeCycle', []);
|
||||
};
|
||||
|
||||
BackgroundMode.prototype = {
|
||||
/**
|
||||
* @public
|
||||
*
|
||||
* Aktiviert den Hintergrundmodus.
|
||||
*/
|
||||
activate: function () {
|
||||
@ -20,9 +23,11 @@ BackgroundMode.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @public
|
||||
*
|
||||
* Deaktiviert den Hintergrundmodus
|
||||
*/
|
||||
deactivate: function (badge) {
|
||||
deactivate: function () {
|
||||
cordova.exec(null, null, 'BackgroundMode', 'deactivate', []);
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user