我無法獲得始終添加區域的startMonitoringForRegion。startMonitoringForRegion並非總是將區域添加到受監視的區域
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;
}
}
}
我在10之後放置了休息區,因爲它從未添加超過10個,並且會在560個區域的某個地方崩潰。甚至將其限制爲10個地址,有時不會添加10個地址,而只能添加8個(或7,9或0)。它不是第一個被添加的8個。
另外,如果我有
NSLog(@"region count %i",[[locationManager monitoredRegions] count]);
剛過廁所總是產生一個錯誤
錯誤,時間,309834541.397,功能, 「布爾CLClientCopyMonitoredRegions(__ CLClient *,常量__CFDictionary **)」,無法成功發送
有關如何成功使用startMonitoringForRegion的任何建議?
編輯:添加@try捕獲startMonitoringForRegion:和[[locationManager monitoredRegions] count],這會產生錯誤。他們的錯誤仍然產生,但沒有發現。還將它全部移到NSTimer循環中,每秒鐘都會觸發它重複的調用導致問題。仍然隨機失敗。有時我的第一次通話失敗。
乾杯
我正在使用iPhone4和區域監視功能並已啓用。 – 2010-10-27 01:49:55
對不起,您的意思是區域監控僅適用於iPhone 4? – Daniel 2011-12-13 17:22:54