mirror of
https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background
synced 2024-11-22 07:14:54 +00:00
Initial iOS support
This commit is contained in:
parent
a79fa641a4
commit
14bf569922
@ -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>
|
||||
|
@ -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
|
@ -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
|
Loading…
Reference in New Issue
Block a user