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

91 lines
2.0 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"
2013-10-09 08:50:15 +00:00
@interface APPBackgroundMode (PrivateMethods)
// Aktiviert den Hintergrundmodus
- (void) activateMode;
// Deaktiviert den Hintergrundmodus
- (void) deactivateMode;
@end
2013-10-08 09:00:36 +00:00
@implementation APPBackgroundMode
2013-10-08 12:36:19 +00:00
@synthesize locationManager;
2013-10-09 08:50:15 +00:00
/**
* @js-interface
*
* Aktiviert den Hintergrundmodus.
*/
- (void) activate:(CDVInvokedUrlCommand *)command
{
[self activateMode];
}
/**
* @js-interface
*
* Deaktiviert den Hintergrundmodus.
*/
- (void) deactivate:(CDVInvokedUrlCommand *)command
{
[self deactivateMode];
}
/**
* @obj-c-interface
*
* Aktiviert den Hintergrundmodus.
*/
2013-10-08 09:00:36 +00:00
- (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
}
2013-10-09 08:50:15 +00:00
/**
* @obj-c-interface
*
* Deaktiviert den Hintergrundmodus.
*/
2013-10-08 09:00:36 +00:00
- (void) deactivateMode
{
2013-10-08 12:36:19 +00:00
if (locationManager) {
[locationManager stopUpdatingLocation];
};
}
2013-10-08 09:00:36 +00:00
2013-10-09 08:50:15 +00:00
/**
* Registriert die Listener für die (sleep/resume) Events und startet bzw. stoppt die Geo-Lokalisierung.
*/
2013-10-08 12:36:19 +00:00
- (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