Last active
August 29, 2015 14:02
-
-
Save edewit/09b26eb57f3896a4fd92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView { | |
self = (GeofencingPlugin*)[super initWithWebView:(UIWebView*)theWebView]; | |
if (self) { | |
self.locationManager = [[CLLocationManager alloc] init]; | |
self.locationManager.delegate = self; // Tells the location manager to send updates to this object | |
} | |
self.locationManager.distanceFilter = kCLLocationAccuracyBest; | |
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; | |
[self.locationManager startUpdatingLocation]; | |
// Set a movement threshold for new events. | |
locationManager.distanceFilter = 100; // meters | |
[locationManager startUpdatingLocation]; | |
return self; | |
} | |
- (void)startSignificantChangeUpdates | |
{ | |
locationManager.delegate = self; | |
[locationManager startMonitoringSignificantLocationChanges]; | |
} | |
- (void)locationManager:(CLLocationManager *)manager | |
didUpdateLocations:(NSArray *)locations { | |
// If it's a relatively recent event, turn off updates to save power. | |
CLLocation* location = [locations lastObject]; | |
NSDate* eventDate = location.timestamp; | |
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow]; | |
if (abs(howRecent) < 15.0) { | |
entered = NO; | |
} | |
} | |
- (void)notify { | |
if (entered) { | |
[self notify:region withStatus:@"entered"]; | |
} | |
} | |
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { | |
entered = YES; | |
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(notify:) userInfo:nil repeats:NO]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment