cordova-plugin-run-in-backg.../src/ios/APPBackgroundMode.m

52 lines
1.5 KiB
Mathematica
Raw Normal View History

2013-10-08 09:00:36 +00:00
/**
* APPBackgroundMode.m
* Cordova BackgroundMode Plugin
*
* Created by Sebastian Katzer (github.com/katzer) on 08/10/2013.
* Copyright 2013 Sebastian Katzer. All rights reserved.
* GPL v2 licensed
*/
#import "APPBackgroundMode.h"
@implementation APPBackgroundMode
2013-10-08 12:36:19 +00:00
@synthesize locationManager;
2013-10-08 09:00:36 +00:00
// Aktiviert den Hintergrundmodus
- (void) activateMode
{
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
}
// Deaktiviert den Hintergrundmodus
- (void) deactivateMode
{
2013-10-08 12:36:19 +00:00
if (locationManager) {
[locationManager stopUpdatingLocation];
};
}
2013-10-08 09:00:36 +00:00
2013-10-08 12:36:19 +00:00
// Registriert sich 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];
}
2013-10-08 09:00:36 +00:00
}
@end