2013-10-08 66 views
14

在使用信標(iOS設備)進行測試時,我發現監聽器信標給出了一些意外的行爲。 locationManager:didEnterRegion即使信標進入區域,方法也不會被調用。但locationManager:didRangeBeacons:inRegion:正在調用正確,並且在那裏顯示檢測到的信標。有沒有人經歷過這樣的事情?locationManager:當檢測到信標時不會調用didEnterRegion

+0

經過問題掙扎1.5天后。問題出在飛機模式。如果啓用了飛行模式,則iBeacon的測距功能完好,但不能監測。遺憾的是沒有任何錯誤或任何 – bpolat

回答

7

很難說如果我沒有看到完全相同的東西,沒有關於測試開始條件的更多細節。但是,是的,在某些特定情況下,我看到了locationManager:didRangeBeacons:inRegion即使沒有調用locationManager:didEnterRegion也會被調用。

如果您在同一地區同時開始測距和監控,並且iOS認爲您在已在處於受監控的地區,那麼您可能無法調用locationManager:didEnterRegion。

要真正測試,如果有什麼不妥,你需要建立一個測試用例,你:

  1. 確保你是不是在該地區。
  2. 讓iOS的幾分鐘運行
  3. 開始監視區域
  4. 讓iOS的繼續幾分鐘
  5. 輸入區域運行。
  6. 看看你得到的LocationManager一個電話:didEnterRegion

如果你還是不通過上面的準備後接到一個電話,然後東西肯定是不對的。

+0

我進入該地區後開始傳輸。在這種情況下,它應該叫..對嗎?一旦我通過停止發送而退出該區域,然後我再次開始發送,它的工作就像被感知(didEnterRegion被調用)。 –

+0

*你*認爲你進入該地區並不重要。 :)所有重要的是iOS LocationManager認爲的事情,它的當前狀態對你來說是不可見的。您需要100%確定它不認爲它已經在您開始監控時定義的區域中,因爲如果它認爲它已經在區域中,則可能無法獲得回撥。這就是爲什麼我建議上述程序 - 它確保iOS在測試開始時將您識別爲在區域之外。 – davidgyoung

+0

讓我以另一種方式提出這個問題......如果您報告的問題是可重複的,那麼您在評論中所說的內容與您所說的內容在原始文章中無效之間有什麼區別?你重新啓動你的手機嗎?你等了很長時間嗎?重複失敗需要什麼? – davidgyoung

31

檢查您的方法是否按照以下方式實施。 在viewDidLoad,開始在端

self.beaconRegion.notifyOnEntry=YES; 
self.beaconRegion.notifyOnExit=YES; 
self.beaconRegion.notifyEntryStateOnDisplay=YES; 
[self.locationManager startMonitoringForRegion:self.beaconRegion]; 

監測開始後moniotoring,請求狀態爲您的限定區域

- (void) locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region 
{ 
    [self.locationManager requestStateForRegion:self.beaconRegion]; 
} 

確定狀態後,開始測距信標

-(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region 
{ 
    if (state == CLRegionStateInside) 
    { 
     //Start Ranging 
     [manager startRangingBeaconsInRegion:self.beaconRegion]; 
    } 
    else 
    { 
     //Stop Ranging here 
    } 
} 

和實施以下方法根據您的需要...

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region 
{ 
    [email protected]"Entered region"; 
} 

-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region 
{ 
    [email protected]"Exited region"; 
} 

-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region 
{ 
    if(beacons.count>0) 
    {} 
} 

希望這能解決您的問題。

+1

您的清單非常有幫助,thx! –

+0

感謝您喜歡u_b ... –

+0

令人驚歎的解釋。非常感謝你。 – MeV

12
before starting coding in project , you must follow given setup guidlines --> 
1. in project info or info.plist --> 
     Custom IOS Target Properties --> 
        . add "Required background modes" 
        . in this add two items --> 
           ."App shares data using CoreBluetooth" 
           ."App registers for location updates" 
2. in project Capability --> 
     There is Background Modes 
        . check "Loaction update" 
        . check "Acts as a Bluetooth LE accessory" 
        . check "uses bluetooth LE accessories" 

(和不遵循Davidgyoung先生的指示相信我,這肯定會工作。)

+0

好答案。爲我工作.. –

+0

如果您的應用程序是BLE中心,則需要在所需的背景模式下設置「使用CoreBluetooth進行應用程序通信」。如果您的應用程序是BLE外設,您需要設置「使用CoreBluetooth的應用程序共享數據」 – mezulu

6

您還需要了解你正在監視區域 - 不是特定信標。

所以,如果你有3個信號燈共享相同proximityUUID和您所在的區域被定義爲僅proximityUUID(不包括主要和次要值),您將得到只有在兩種情況下通知:從

  1. 無標區域是在範圍和第一個信標/信標被 發現(didEnterRegion:

    從區域
  2. 一個或多個信標是在範圍內,他們都出去的視線 〜30秒(didExitRegion:

+0

這對我有幫助。謝謝。 –

相關問題