问题
在做一款基于蓝牙BLE通信的智能硬件,设备的蓝牙服务是动态变化的,发现 IOS 存在蓝牙服务缓存。
具体表现是,IOS 搜索发现过硬件的蓝牙服务后,断开蓝牙连接,设备重启更新了蓝牙服务, IOS 再次搜索,扫描到的蓝牙服务仍然是旧的。
原因
事实上,缓存现象不是 IOS 独有的,在 BLE 规范中定义了缓存标准,参考 蓝牙4.0规范 vol 3, Part G, 2.5.2 Attribute Caching。这是为了优化,在客户端重新连接服务端时,可以重用上次发现的蓝牙服务信息。
Attribute caching is an optimization that allows the client to discover the Attribute information such as Attribute Handles used by the server once and use
the same Attribute information across reconnections without rediscovery. Without caching the Attribute information, the client shall rediscover the Attribute
information at each reconnection. With caching, time is saved and a significant
amount of packets exchanged between the client and server is not required.
The Attribute information that shall be cached by a client is the Attribute H