Skip to content

Commit

Permalink
Considering and old issue as well: Lyokone#36
Browse files Browse the repository at this point in the history
  • Loading branch information
PerrchicK committed Mar 7, 2019
1 parent 866bd94 commit 9f3acf3
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion ios/Classes/LocationPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,13 @@ -(BOOL) isPermissionGranted {
-(FlutterError*)onListenWithArguments:(id)arguments eventSink:(FlutterEventSink)events {
self.flutterEventSink = events;
self.flutterListening = YES;
[self.clLocationManager startUpdatingLocation];

if ([self isPermissionGranted]) {
[self.clLocationManager startUpdatingLocation];
} else {
[self requestPermission];
}

return nil;
}

Expand All @@ -137,6 +143,8 @@ -(FlutterError*)onCancelWithArguments:(id)arguments {
return nil;
}

#pragma mark - CLLocationManagerDelegate Methods

-(void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray<CLLocation*>*)locations {
CLLocation *location = locations.firstObject;
NSDictionary<NSString*,NSNumber*>* coordinatesDict = @{
Expand All @@ -160,4 +168,18 @@ -(void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray<C
}
}

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (status == kCLAuthorizationStatusDenied) {
// The user denied authorization
NSLog(@"User denied permissions");
}
else if (status == kCLAuthorizationStatusAuthorizedWhenInUse || status == kCLAuthorizationStatusAuthorizedAlways) {
NSLog(@"User granted permissions");

if (self.locationWanted || self.flutterListening) {
[self.clLocationManager startUpdatingLocation];
}
}
}

@end

0 comments on commit 9f3acf3

Please sign in to comment.