mirror of
https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background
synced 2024-11-22 15:24:54 +00:00
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 <Cordova/CDVPlugin.h>
|
||||||
#import <CoreLocation/CoreLocation.h>
|
#import <CoreLocation/CoreLocation.h>
|
||||||
|
|
||||||
@interface APPBackgroundMode : CDVPlugin
|
@interface APPBackgroundMode : CDVPlugin {
|
||||||
|
BOOL _activated;
|
||||||
|
}
|
||||||
|
|
||||||
// Aktiviert den Hintergrundmodus
|
// Aktiviert den Hintergrundmodus
|
||||||
- (void) activate:(CDVInvokedUrlCommand *)command;
|
- (void) activate:(CDVInvokedUrlCommand *)command;
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
@interface APPBackgroundMode (PrivateMethods)
|
@interface APPBackgroundMode (PrivateMethods)
|
||||||
|
|
||||||
|
// Registriert die Listener für die (sleep/resume) Events
|
||||||
|
- (void) observeLifeCycle:(CDVInvokedUrlCommand *)command;
|
||||||
// Aktiviert den Hintergrundmodus
|
// Aktiviert den Hintergrundmodus
|
||||||
- (void) activateMode;
|
- (void) activateMode;
|
||||||
// Deaktiviert den Hintergrundmodus
|
// Deaktiviert den Hintergrundmodus
|
||||||
@ -22,6 +24,16 @@
|
|||||||
|
|
||||||
@synthesize locationManager;
|
@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
|
* @js-interface
|
||||||
*
|
*
|
||||||
@ -49,6 +61,43 @@
|
|||||||
*/
|
*/
|
||||||
- (void) activateMode
|
- (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) {
|
if (!locationManager) {
|
||||||
locationManager = [[CLLocationManager alloc] init];
|
locationManager = [[CLLocationManager alloc] init];
|
||||||
};
|
};
|
||||||
@ -64,28 +113,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @obj-c-interface
|
* Beendet das Aktualisieren des Standpunktes.
|
||||||
*
|
|
||||||
* Deaktiviert den Hintergrundmodus.
|
|
||||||
*/
|
*/
|
||||||
- (void) deactivateMode
|
- (void) stopUpdatingLocation
|
||||||
{
|
{
|
||||||
if (locationManager) {
|
if (locationManager) {
|
||||||
|
// Beendet das Aktualisieren des Standpunktes
|
||||||
[locationManager stopUpdatingLocation];
|
[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
|
@end
|
@ -8,11 +8,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var BackgroundMode = function () {
|
var BackgroundMode = function () {
|
||||||
|
// Registriert die Listener für die (sleep/resume) Events
|
||||||
|
cordova.exec(null, null, 'BackgroundMode', 'observeLifeCycle', []);
|
||||||
};
|
};
|
||||||
|
|
||||||
BackgroundMode.prototype = {
|
BackgroundMode.prototype = {
|
||||||
/**
|
/**
|
||||||
|
* @public
|
||||||
|
*
|
||||||
* Aktiviert den Hintergrundmodus.
|
* Aktiviert den Hintergrundmodus.
|
||||||
*/
|
*/
|
||||||
activate: function () {
|
activate: function () {
|
||||||
@ -20,9 +23,11 @@ BackgroundMode.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @public
|
||||||
|
*
|
||||||
* Deaktiviert den Hintergrundmodus
|
* Deaktiviert den Hintergrundmodus
|
||||||
*/
|
*/
|
||||||
deactivate: function (badge) {
|
deactivate: function () {
|
||||||
cordova.exec(null, null, 'BackgroundMode', 'deactivate', []);
|
cordova.exec(null, null, 'BackgroundMode', 'deactivate', []);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user