开发者

startMonitoringForRegion not always adding regions to monitoredRegions

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 startMonitoringFo开发者_开发百科rRegion: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


In the Location Awareness Programming Guide

You should always be judicious when specifying the set of regions to monitor. Regions are a shared system resource and the total number of regions available systemwide is limited. For this reason, Core Location limits the number of regions that may be simultaneously monitored by a single application.


are you using iPhone4 feature only works on that device, check with

 [CLLocationManager regionMonitoringAvailable] 


This appears to be a database error or something analogous. For some period of time after the region is registered, the table is locked (or, again, whatever the equivalent is behind the scenes, though I'm guessing it's exactly that). Therefore you can't do a count. Try counting after a longer period.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜