2013-12-09 12:36:43 +00:00
|
|
|
/*
|
2014-02-13 13:17:05 +00:00
|
|
|
Copyright 2013-2014 appPlant UG
|
2013-12-09 12:36:43 +00:00
|
|
|
|
|
|
|
Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
or more contributor license agreements. See the NOTICE file
|
|
|
|
distributed with this work for additional information
|
|
|
|
regarding copyright ownership. The ASF licenses this file
|
|
|
|
to you under the Apache License, Version 2.0 (the
|
|
|
|
"License"); you may not use this file except in compliance
|
|
|
|
with the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing,
|
|
|
|
software distributed under the License is distributed on an
|
|
|
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
KIND, either express or implied. See the License for the
|
|
|
|
specific language governing permissions and limitations
|
|
|
|
under the License.
|
|
|
|
*/
|
2013-10-08 09:00:36 +00:00
|
|
|
|
|
|
|
#import "APPBackgroundMode.h"
|
|
|
|
|
2013-10-09 08:50:15 +00:00
|
|
|
@interface APPBackgroundMode (PrivateMethods)
|
|
|
|
|
2013-10-09 09:40:06 +00:00
|
|
|
// Registriert die Listener für die (sleep/resume) Events
|
|
|
|
- (void) observeLifeCycle:(CDVInvokedUrlCommand *)command;
|
2013-10-09 08:50:15 +00:00
|
|
|
// Aktiviert den Hintergrundmodus
|
2013-10-09 12:54:23 +00:00
|
|
|
- (void) enableMode;
|
2013-10-09 08:50:15 +00:00
|
|
|
// Deaktiviert den Hintergrundmodus
|
2013-10-09 12:54:23 +00:00
|
|
|
- (void) disableMode;
|
2013-10-09 08:50:15 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2013-10-08 09:00:36 +00:00
|
|
|
@implementation APPBackgroundMode
|
|
|
|
|
2013-10-08 12:36:19 +00:00
|
|
|
@synthesize locationManager;
|
|
|
|
|
2013-10-09 09:40:06 +00:00
|
|
|
/**
|
|
|
|
* @js-interface
|
|
|
|
*
|
|
|
|
* Registriert die Listener für die (sleep/resume) Events.
|
|
|
|
*/
|
|
|
|
- (void) observeLifeCycle:(CDVInvokedUrlCommand *)command
|
|
|
|
{
|
|
|
|
// Methode pluginInitialize wird aufgerufen, falls Instanz erstellt wurde
|
|
|
|
}
|
|
|
|
|
2013-10-09 08:50:15 +00:00
|
|
|
/**
|
|
|
|
* @js-interface
|
|
|
|
*
|
|
|
|
* Aktiviert den Hintergrundmodus.
|
|
|
|
*/
|
2013-10-09 12:54:23 +00:00
|
|
|
- (void) enable:(CDVInvokedUrlCommand *)command
|
2013-10-09 08:50:15 +00:00
|
|
|
{
|
2013-10-09 12:54:23 +00:00
|
|
|
[self enableMode];
|
2013-10-09 08:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @js-interface
|
|
|
|
*
|
|
|
|
* Deaktiviert den Hintergrundmodus.
|
|
|
|
*/
|
2013-10-09 12:54:23 +00:00
|
|
|
- (void) disable:(CDVInvokedUrlCommand *)command
|
2013-10-09 08:50:15 +00:00
|
|
|
{
|
2013-10-09 12:54:23 +00:00
|
|
|
[self disableMode];
|
2013-10-09 08:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Aktiviert den Hintergrundmodus.
|
|
|
|
*/
|
2013-10-09 12:54:23 +00:00
|
|
|
- (void) enableMode
|
2013-10-08 09:00:36 +00:00
|
|
|
{
|
2013-10-09 12:54:23 +00:00
|
|
|
_enabled = true;
|
2013-10-09 09:40:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deaktiviert den Hintergrundmodus.
|
|
|
|
*/
|
2013-10-09 12:54:23 +00:00
|
|
|
- (void) disableMode
|
2013-10-09 09:40:06 +00:00
|
|
|
{
|
2013-10-09 12:54:23 +00:00
|
|
|
_enabled = false;
|
2013-10-09 09:40:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registriert die Listener für die (sleep/resume) Events und startet bzw. stoppt die Geo-Lokalisierung.
|
|
|
|
*/
|
|
|
|
- (void) pluginInitialize
|
|
|
|
{
|
2013-10-09 12:54:23 +00:00
|
|
|
[self enableMode];
|
2013-10-09 09:40:06 +00:00
|
|
|
|
|
|
|
if (&UIApplicationDidEnterBackgroundNotification && &UIApplicationWillEnterForegroundNotification) {
|
2013-10-09 12:54:23 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(activateMode) name:UIApplicationDidEnterBackgroundNotification object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deactivateMode) name:UIApplicationWillEnterForegroundNotification object:nil];
|
2013-10-09 09:40:06 +00:00
|
|
|
} else {
|
2013-10-09 12:54:23 +00:00
|
|
|
[self activateMode];
|
2013-10-09 09:40:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Startet das Aktualisieren des Standpunktes.
|
|
|
|
*/
|
2013-10-09 12:54:23 +00:00
|
|
|
- (void) activateMode
|
2013-10-09 09:40:06 +00:00
|
|
|
{
|
2013-10-09 12:54:23 +00:00
|
|
|
if (_enabled == false) {
|
2013-10-09 09:40:06 +00:00
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2013-10-08 12:36:19 +00:00
|
|
|
if (!locationManager) {
|
|
|
|
locationManager = [[CLLocationManager alloc] init];
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef __IPHONE_6_0
|
|
|
|
locationManager.activityType = CLActivityTypeFitness;
|
|
|
|
#endif
|
2013-10-08 09:00:36 +00:00
|
|
|
|
2013-10-08 12:36:19 +00:00
|
|
|
// Empfängt nur Nachrichten, wenn sich die Position um 1km geändert hat
|
|
|
|
locationManager.distanceFilter = 1000;
|
|
|
|
// Startet das Aktualisieren des Standpunktes
|
|
|
|
[locationManager startUpdatingLocation];
|
2013-10-08 09:00:36 +00:00
|
|
|
}
|
|
|
|
|
2013-10-09 08:50:15 +00:00
|
|
|
/**
|
2013-10-09 09:40:06 +00:00
|
|
|
* Beendet das Aktualisieren des Standpunktes.
|
2013-10-09 08:50:15 +00:00
|
|
|
*/
|
2013-10-09 12:54:23 +00:00
|
|
|
- (void) deactivateMode
|
2013-10-08 09:00:36 +00:00
|
|
|
{
|
2013-10-08 12:36:19 +00:00
|
|
|
if (locationManager) {
|
2013-10-09 09:40:06 +00:00
|
|
|
// Beendet das Aktualisieren des Standpunktes
|
2013-10-08 12:36:19 +00:00
|
|
|
[locationManager stopUpdatingLocation];
|
|
|
|
};
|
|
|
|
}
|
2013-10-08 09:00:36 +00:00
|
|
|
|
|
|
|
@end
|