Is there a way to discover BLE peripheral service faster?

前端 未结 2 926
渐次进展
渐次进展 2021-01-18 19:11

I find that my implementation of the BLE protocol in iOS7 to be very slow in the start up phase. The startup sequence amounts to ~68% of the whole execution time in my app.<

相关标签:
2条回答
  • 2021-01-18 19:50

    There's no framework-level API to improve the discovery speed. BTLE is co-existing with Classic Bluetooth (at the system framework level) and Wi-Fi (at the antenna level), so the maximum time on antenna is limited by the system.

    0 讨论(0)
  • 2021-01-18 20:03

    When you encrypt the connection, iOS should cache the GATT database. Therefore, subsequent discovery calls after the first one should happen instantaneously.

    Since iOS 7, even characteristic values are cached, meaning that you can read static values like a "Device name" through the characteristic's value property. If you want to update them, you still have to issue a Read Characteristic Value request.

    For details regarding the caching behavior, check WWDC 2013 session 703 from slide 48 (should probably watch the corresponding part in the video).

    For connection and discovery time, it's mainly the advertisement interval. There are a couple of advertisement intervals that are recommended by Apple for best performance in the Bluetooth Accessory Design Guidelines For Apple Products (section 3.5 Advertising Interval). Also, you should disable scanning when you connect, as scanning slows down the connection process by about 55x.

    Note that the iOS based limitations on the number of packets sent per connection event should not affect discovery time noticeably (unless you have a giant GATT database and are querying the whole thing). Those limitations should only become visible for "Write Without Response" and "Characteristic Value Notification", as per the LE protocol design.

    0 讨论(0)
提交回复
热议问题