簡體   English   中英

iOS Core Bluetooth:在外圍設備上未發現廣告服務

[英]iOS Core Bluetooth: Advertised service is not discovered on peripheral

在連接到廣告我感興趣的特定服務的BLE設備之后,為了發現這項服務,我打電話給:

[self.peripheral discoverServices:@[[self.class serviceUUID]]];

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error委托方法被調用而沒有錯誤,但是為外設返回的服務數是0,因此沒有進一步發現特征。 有誰知道為什么會這樣? 提前致謝!

以下是委托方法的完整主體。

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
    if (error) {
        NSLog(@"didDiscoverServices failed: %@", error);
        return;
    }

    NSLog(@"didDiscoverServices succeeded for peripheral: %@.", peripheral.name);
    NSLog(@"Number of services: %d", peripheral.services.count);

    for (CBService *s in peripheral.services) {
        NSLog (@"Discovered service UUID: %@", s.UUID);
        if ([s.UUID isEqual:[self.class serviceUUID]]) {
            NSLog(@"Discover characteristics...");
            [self.peripheral discoverCharacteristics:@[[self.class controlPointCharacteristicUUID], [self.class packetCharacteristicUUID]] forService:s];
        }
    }
}

控制台顯示:

2014-11-27 15:54:51.933 k[197:13362] didDiscoverServices succeeded for peripheral: BootK
2014-11-27 15:54:51.934 k[197:13362] Number of services: 0

我唯一能想到的是[self.class serviceUUID]與您正在尋找的服務的UUID不匹配。 當您啟動掃描時,是否按服務UUID進行過濾?

[self.centralManager scanForPeripheralsWithServices:[self.class serviceUUID] options:nil];

如果沒有,這可以解釋為什么您能夠發現並連接到它,但不能發現該特定服務。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM