Initial iOS support

This commit is contained in:
Sebastián Katzer 2013-10-08 14:36:19 +02:00
parent a79fa641a4
commit 14bf569922
3 changed files with 36 additions and 0 deletions

View File

@ -25,6 +25,13 @@
</feature>
</config-file>
<config-file target="*-Info.plist" parent="CFBundleURLTypes">
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
</config-file>
<header-file src="src/ios/APPBackgroundMode.h" />
<source-file src="src/ios/APPBackgroundMode.m" />
</platform>

View File

@ -9,6 +9,7 @@
#import <Foundation/Foundation.h>
#import <Cordova/CDVPlugin.h>
#import <CoreLocation/CoreLocation.h>
@interface APPBackgroundMode : CDVPlugin
@ -17,4 +18,6 @@
// Deaktiviert den Hintergrundmodus
- (void) deactivateMode;
@property (nonatomic, strong) CLLocationManager* locationManager;
@end

View File

@ -11,16 +11,42 @@
@implementation APPBackgroundMode
@synthesize locationManager;
// Aktiviert den Hintergrundmodus
- (void) activateMode
{
if (!locationManager) {
locationManager = [[CLLocationManager alloc] init];
};
#ifdef __IPHONE_6_0
locationManager.activityType = CLActivityTypeFitness;
#endif
// Empfängt nur Nachrichten, wenn sich die Position um 1km geändert hat
locationManager.distanceFilter = 1000;
// Startet das Aktualisieren des Standpunktes
[locationManager startUpdatingLocation];
}
// Deaktiviert den Hintergrundmodus
- (void) deactivateMode
{
if (locationManager) {
[locationManager stopUpdatingLocation];
};
}
// 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];
}
}
@end