I can not get startMonitoringForRegion to consistently add regions.
int i =0;
for(Deals *d in deals){
NSLog(@"deal addRegionsInDealsArray %@",d.deal_id);
if (d.latitude != NULL && d.longitude!=NULL &&
![d.latitude isEqualToNumber:[NSNumber numberWithInt:0 ]] &&
![d.longitude isEqualToNumber:[NSNumber numberWithInt:0 ]]) {
CLLocationCoordinate2D dl = CLLocationCoordinate2DMake(
[d.latitude doubleValue],
[d.longitude doubleValue]);
//NSLog(@"Lat addRegionsInDealsArray %@",d.latitude);
CLRegion * clr = [[CLRegion alloc] initCircularRegionWithCenter:dl radius:radius identifier:d.deal_id];
[locationManager startMonitoringForRegion:clr desiredAccuracy:kCLLocationAccuracyHundredMeters];
NSLog(@"Region to add:%@",clr);
[clr release];
i++;
if (i==10) {
break;
}
}
}
I put the break after 10 because it never added more than 10 and would crash somewhere around 560 regions. even limiting it to 10 regins it sometimes does not add 10 but only 8 (or 7, 9 or 0). It is not the first 8 that get added.
Also if I have
NSLog(@"region count %i",[[locationManager monitoredRegions] count]);
just after the loo it always produces an error
ERROR,Time,309834541.397,Function,"Boolean CLClientCopyMonitoredRegions(__CLClient*, const __CFDictionary**)",Could not send successfully
Any suggestions on how to use startMonitoringForRegion successfully?
edit: added @try catch around the startMonitoringForRegion: and the [[locationManager monitoredRegions] count] which produces an error. they error is still produces but not caught. Also moved it all to NSTimer loop that fires every second in can it was repeated calls causing problem. still fails randomly. sometimes my first call fails.
Cheers