How to clear BLE cache in IOS ?

As per the iOS Bluetooth Framework, iOS device cache the BLE peripheral services.
I am using Nordic s130 nrf51822 chipset for BLE communication.
Now When I add the BLE device into my iOS app. its services get cached. But as per the Nordic documentation when you have services changed in future, You need to add an IS_Service_Changed (0x2A05) flag in your bootloader mode as well as in application mode.


We have added that under generic attribute service i.e 0x1801. Now when I changed the services, iOS should get the service change callback in peripherals

didModifyServices delegate method. But I am not able to get the callback for didModifyServices.

As per the apple Bluetooth design guidelines here: https://developer.apple.com/hardwaredrivers/BluetoothDesignGuidelines.pdf

Some services handled internally by IOS and not shown to third party apps. (explained in 3.12 GATT Server) it includes

  • Generic Attribute Profile Service
  • Generic Access Profile Service
  • Bluetooth Low Energy HID Service
  • Apple Notification Center Service

So, How I will get a callback for didModifyServices?How can I clear the BLE cache programmatically?


Note: I am not using Bonded connection for BLE.I have also tried to turn Bluetooth ON/OFF and still the BLE cache not get clear.

Replies

Hi nikhil,
I see you posted this question one year ago.
I'm currently dealing with the same issue and I have not been able to find yet a solution.
The BLE peripheral I'm working on correctly manages and displays the GAP service with its Service changed characteristic.
But when the devices goes into DFU mode and the Apple device gets disconnected as a consequence, when reconnecting (even after re-scanning for peripherals in range), CoreBluetooth is still caching the previously readed GATT table for that peripheral.
Were you able to find a solution for this situation ?
Thanks in advance,

hi,nicolas.velco:


Did you solve the problem?I meet the same problem as you.


When enter into DFU mode,iphone can not find the newly added service.


So we can not continue to update our device's firmware.

I struggled with a solution for this as well. After working on this with our firmware department it appears the Peripheral needs to expose the Generic Access Service as well as the Generic Attribute Service. Once both are present the didModifyService will work as described in documentation. If you don't have the ability to change the firmware it simply will not work.


What we did to discover this

Documentation is thin, we had to create a simple Peripheral in xcode to see what hidden services apple creates at default. Inspecting this iOS peripheral with a non-iOS BLE sniffer revealed all the stuff the firmware department needed in order to trigger didModifyService. iOS handles several services internally and doesnt expose them to the programmer as stated above. You will need a BLE sniffer that will not hide these services to understand the requirements.

I have found that forgetting a device and then turning bluetooth off and back on again will refresh the cache and allow me to see changes in characteristics, encryption, etc.

I am doing BLE device development with a Nordic chipset running the S112 soft core and bumped into this problem too. I was seeing odd artifacts and differences between what was advertised vs. what was available after making the BLE connection.

I got things working properly by enabling the Service Changed Nordic SDK configuration value in sdk_config.h. This sends the appropriate service changed notification to the host (iOS in this case) instructing the host to clear previously cached data about the peripheral when the connection is made.

Code Block
#define NRF_SDH_BLE_SERVICE_CHANGED 1


After building the firmware and loading it into the device all of the services and characteristics I had worked hard to create were displayed and behaving properly.

Good luck to all who travel here - I hope that you can get things working properly for you too.