2014-11-24 50 views
4

我在掃描硬件設備。 在前景中,我可以看到設備。 當我開始前景掃描,不是移動到背景,比我打開硬件-BLE,掃描停止,並且該應用無法檢測到硬件。BLE掃描在進入背景時會停止嗎?

如果我打開後面的應用前景,它然後繼續掃描,發現該設備。

我已經設置了鍵:

<string>bluetooth-peripheral</string> 
     <string>bluetooth-central</string> 

,並在後臺模式:

location updates 
external accessory communication 
uses BLE accessories 
acts as BLE ACCESSORY 

但一無所獲。系統不會讓我在背景上檢測設備,只能在前臺檢測設備。

我在想什麼?

回答

0

發現,你必須設置你的後臺尋找,否則將無法正常工作的服務ID。 無論如何,在後臺掃描是非常慢,並可能需要幾分鐘才能檢測!

[_centralManager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:DEVICE_INFO_SERVICE_UUID]] 
0

可以掃描在後臺只對特定serviceUUID BLE,你可以通過零,因爲我們對前景掃描做掃描。

同時,還要確保你開始在主線程的BLE掃描和下面設置正確的選項。

NSArray *services = @[[CBUUID UUIDWithString:UUID1],[CBUUID UUIDWithString:UUID2],[CBUUID UUIDWithString:UUID3]]; 
dispatch_async(dispatch_get_main_queue(), ^{ 
    [self.coreBluetoothManager scanForPeripheralsWithServices:services options:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], CBCentralManagerScanOptionAllowDuplicatesKey, nil]]; 
});