在重新连接时,iPhone不会在蓝牙LE标签上发现服务 [英] iPhone does not discover Services on a Bluetooth LE tag on reconnection

查看:225
本文介绍了在重新连接时,iPhone不会在蓝牙LE标签上发现服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发适用于iOS的蓝牙LE应用程序。我在iOS中使用Core蓝牙框架来处理所有通信。

I am working on a Bluetooth LE application for iOS. I am using the Core Bluetooth framework within iOS to handle all communications.

问题&说明:

当我使用单个标签时,尽管连接和断开连接很多,但是单个标签无缝连接,手机会发现它的服务。



此外,当多个蓝牙LE标签首次连接时,它们无缝连接,手机会发现他们的服务。


当标签时断开然后重新连接到手机,标签连接正常。但是这两个标签中的一个(任一个)似乎没有宣传其服务。即当应用程序打开且标记重新连接时, DiscoverServices 方法不会调用 didDiscoverServices 委托。

When I use a single tag, despite numerous connections and disconnections, the single tag connects seamlessly and the phone discovers it services.

Also, when multiple Bluetooth LE tags connect for the first time, they connect seamlessly and the phone discovers their services.

When the tags get disconnected and then reconnect to the phone, the tags connect fine. But one of the two tags (either one) does not seem to advertise its services. i.e when the app is open and the tag reconnects, the DiscoverServices method does not call the didDiscoverServices delegate.

为什么只有在与多个设备连接时才会发生这种情况。

Why is this happening only when connection with multiple devices takes place.

我设置了 peripheral.delegate 正确。我已经尝试了一切,包括重复重新连接,重复DiscoverServices调用标签。似乎没什么用。

I have set the peripheral.delegate correctly. I have tried everything, including doing repeated re-connect, repeated DiscoverServices calls to the tag. Nothing seems to work.

如何重新连接到手机的多个标签,仍然可以发现所有服务。




请帮助



谢谢,

Manju

How can I re-connect to multiple tags to the phone and still discover all services.

Please help

Thanks,
Manju

推荐答案

原来我在 didDiscovercharacteristicsForService didDiscovercharacteristicsForService em> 导致连接不稳定的委托方法。



如果您遇到类似问题,我建议您在没有任何干预(任何类型)的情况下完成委托方法,并将CBPeripheral传递给您设计的另一个函数,用于传递任何值/向设备发出命令。



无论如何,谢谢Wilhemsen。

Turns out that there was command I was issuing to the device in the"didDiscovercharacteristicsForService" delegate method which was causing the connection instability.

If you are facing similar issues, I suggest you to let the delegate method complete without any intervention (of any kind) and pass the CBPeripheral to another function designed by you to pass any values / issue a command to the devices.

Thanks anyway Wilhemsen.

所以步骤如下。

1>搜索标签,

2>如果在范围内,CONNECT to Tag

3>如果已连接,请调用DISCOVER服务方法(不要中断)

4>在DidDiscoverServices中,调用DISCOVER特征方法

..

在DidDiscoverCharacteristics方法中,等到发现所有特征..
然后,最后,在代码中调用一个函数来执行必要的设置。

.. 。

代码示例

-(void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error
{

    for (int i=0; i < peripheral.services.count; i++) {
        CBService *s = [peripheral.services objectAtIndex:i];
        printf("Fetching characteristics for service with UUID : %s\r\n",[self CBUUIDToString:s.UUID]);
        [peripheral discoverCharacteristics:nil forService:s];
    }

}


- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{        
    if (!error)
    {
        CBService *s = [peripheral.services objectAtIndex:(peripheral.services.count - 1)];
        if([self compareCBUUID:service.UUID UUID2:s.UUID])
        {
           // This is when the **Tag** is completely connected to the Phone and is in a mode where it can accept Instructions from Device well.

            printf("Finished discovering characteristics");
           // Now Do the Setup of the Tag
            [self setupPeripheralForUse:peripheral];

        }
    }

    else
    {
        printf("Characteristic discorvery unsuccessfull !\r\n");
    }
}

-(void) setupPeripheralForUse:(CBPeripheral *)peripheral
{

    // DO all your setup in this function. Separate Perpiheral Setup from the process that synchronizes the tag and the phone. 

}

这篇关于在重新连接时,iPhone不会在蓝牙LE标签上发现服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆