Reputation: 341
I am developing a Reminder App,i have enable geofencing in that App. the Region Radius is 100m, when the user entered into that location, DIdEnterRegion does not get called, even i leave that location,didExitRegion also get not called. Only startMonitoringRegion is only Called.Here is the Code
- (id)init {
self = [super init];
self.locationMeasurements = [NSMutableArray array];
_locationManager = [[CLLocationManager alloc] init];
[_locationManager setDelegate:self];
[self stopMonitorSpecificRegion];
if ([_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[_locationManager requestWhenInUseAuthorization];
}
_locationManager.distanceFilter = [[NSUserDefaults standardUserDefaults] valueForKey:@"radialDistance"]?[[[NSUserDefaults standardUserDefaults] valueForKey:@"radialDistance"] doubleValue]:kCLDistanceFilterNone; // whenever we move
_locationManager.desiredAccuracy = [[NSUserDefaults standardUserDefaults] valueForKey:@"desiredAccuracy"]?[[[NSUserDefaults standardUserDefaults] valueForKey:@"desiredAccuracy"] doubleValue]:kCLLocationAccuracyHundredMeters;
return self;
}
Upvotes: 0
Views: 744
Reputation: 253
Add this code
- (void) locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
{
[self.locationManager requestStateForRegion:yourregion];
}
Upvotes: 0
Reputation: 31
If [locationmanager requestAlwaysAuthorization] also doesn't work then click on xCode project, goto target settings and in the Capablities tab click on Background Modes and enable Location Updates.
And here on the above code, you haven't created instance for CLRegion and you should call startMonitoringforRegion method to monitor a region.Below is an example for it. Try this:
CLLocationCoordinate2D region = CLLocationCoordinate2DMake(12.9877899, 13.88999);
CLCircularRegion* regionToMonitor = [[CLCircularRegion alloc] initWithCenter:region radius:500 identifier:@"address"];
[self.locationManager startMonitoringForRegion:regionToMonitor];
Upvotes: 0
Reputation:
This is issue with ios 8 Add this to your code
if (IS_OS_8_OR_LATER)
{
[locationmanager requestWhenInUseAuthorization];
[locationmanager requestAlwaysAuthorization];
}
and to info.plist:
<key>NSLocationUsageDescription</key>
<string>I need location</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>I need location</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>I need location</string>
Upvotes: 1