2010-10-27 23 views
2

我無法獲得始終添加區域的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循環中,每秒鐘都會觸發它重複的調用導致問題。仍然隨機失敗。有時我的第一次通話失敗。

乾杯

回答

0

您正在使用的iPhone4功能只在該設備上,請與

[CLLocationManager regionMonitoringAvailable] 
+0

我正在使用iPhone4和區域監視功能並已啓用。 – 2010-10-27 01:49:55

+0

對不起,您的意思是區域監控僅適用於iPhone 4? – Daniel 2011-12-13 17:22:54

4

在位置感知編程指南

你應該總是明智指定一組時要監測的地區。區域是共享系統資源,全系統可用區域總數有限。因此,Core Location限制了單個應用程序可能同時監視的區域數量。

0

這似乎是一個數據庫錯誤或類似的東西。在該區域註冊後的一段時間內,表格被鎖定(或者,再次,不管在幕後等價物是什麼,儘管我猜測它就是這樣)。因此你不能做點數。嘗試更長時間後計算。