How to get list of names of available bluetooth devices in ios swift?

user5907771

this question is a replica of this qustion

I have declared CBCentralManagerDelegate in my class and var cb = CBCentralManager()

I set the delegate as cb.delegate = self

I search the devices as cb.scanForPeripheralsWithServices(nil, options: nil)

func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber) {
    print("\(advertisementData.description)")
}

I am able to print the details. But in the log I get data like this:

["kCBAdvDataTxPowerLevel": 0, "kCBAdvDataLocalName": Smart Key, "kCBAdvDataManufacturerData": <bc00>, "kCBAdvDataServiceData": {
Battery = <64>;
}, "kCBAdvDataIsConnectable": 1]

All I want is the name of the device like: My2Device

p2pkit

Bluetooth Low Energy supports a protocol which is a bit un-intuitive if you had not experienced it before.

Think about it like that:

  • A BLE devices is called a "peripheral"
  • Each peripheral has an address (which can change on iPhones) and sometime, but not necessarily a name (which is also changeable).
  • Peripherals advertise "services"
  • Each service has "characteristics" (read/write)
  • Each characteristic has value that you can read or write

The best way to get a reliable "name" is to publish a "service" on one device and discover the service on another. If you want to go into the detail, you could also publish characteristics and read a name.

Reasoning: names are inconsistent and can change. But when you publish a service it is likely that you would discover it on the other side...

Hope this helps

By the way: if you app is use case driven and you dont want to get into the details of networking, consider using a SDK/Framework that can do that for you.

For example: http://p2pkit.io or Google Nearby

Disclaimer: I work for Uepaa, developing p2pkit.io for Android and iOS.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

List names of all available MS SQL databases on server using python

来自分类Dev

Windows.Devices.Bluetooth.dll

来自分类Dev

How to present list of names in Presenter?

来自分类Dev

Swift: how exactly do assets work for different sized devices?

来自分类Dev

How to get all available models in Magento?

来自分类Dev

无法注册Windows.Devices.Bluetooth

来自分类Dev

{get}在Swift iOS文档中代表什么?

来自分类Dev

Get list of all city/place names in a country using Nominatim/OpenStreetMap

来自分类Dev

Xcode 5 hangs iOS 7.0.3 devices and logs failed to get the task for process -1

来自分类Dev

How can I *only* get the number of bytes available on a disk in bash?

来自分类Dev

How can I get the amount of available memory portably across distributions?

来自分类Dev

如何在模拟器保存的Swift 5(iOS)中读取JSON文件,该文件位于Library / Developer / CoreSimulator / Devices /

来自分类Dev

Connecting multiple wireless devices to one main device using bluetooth

来自分类Dev

How to make a random names list without repeat in PHP?

来自分类Dev

how to separate a list of names in a text file separated by a space

来自分类Dev

How to get the deltas of a list collection

来自分类Dev

Swift(iOS)-HTTP GET请求未填充PickerView

来自分类Dev

通过Swift(iOS)进行HTTP调用(GET,POST等)

来自分类Dev

share image on twitter and get favourites list from iOS native app

来自分类Dev

Transfer data between iOS and Android via Bluetooth?

来自分类Dev

从iOS在后台扫描Bluetooth LE设备

来自分类Dev

具有iOS ExternalAccessoryFramework的Bluetooth Classic

来自分类Dev

iOS:使用NSTimer写入Bluetooth LE设备

来自分类Dev

iOS - How To Get Touch Points Correctly?

来自分类Dev

"List of devices attached" is empty on Ubuntu 12.04

来自分类Dev

How to get a list with the Typesafe config library

来自分类Dev

How to get a value from keyvalue pair list?

来自分类Dev

How to get file path + file name into a list?

来自分类Dev

How to get list of latest tags in remote git?

Related 相关文章

  1. 1

    List names of all available MS SQL databases on server using python

  2. 2

    Windows.Devices.Bluetooth.dll

  3. 3

    How to present list of names in Presenter?

  4. 4

    Swift: how exactly do assets work for different sized devices?

  5. 5

    How to get all available models in Magento?

  6. 6

    无法注册Windows.Devices.Bluetooth

  7. 7

    {get}在Swift iOS文档中代表什么?

  8. 8

    Get list of all city/place names in a country using Nominatim/OpenStreetMap

  9. 9

    Xcode 5 hangs iOS 7.0.3 devices and logs failed to get the task for process -1

  10. 10

    How can I *only* get the number of bytes available on a disk in bash?

  11. 11

    How can I get the amount of available memory portably across distributions?

  12. 12

    如何在模拟器保存的Swift 5(iOS)中读取JSON文件,该文件位于Library / Developer / CoreSimulator / Devices /

  13. 13

    Connecting multiple wireless devices to one main device using bluetooth

  14. 14

    How to make a random names list without repeat in PHP?

  15. 15

    how to separate a list of names in a text file separated by a space

  16. 16

    How to get the deltas of a list collection

  17. 17

    Swift(iOS)-HTTP GET请求未填充PickerView

  18. 18

    通过Swift(iOS)进行HTTP调用(GET,POST等)

  19. 19

    share image on twitter and get favourites list from iOS native app

  20. 20

    Transfer data between iOS and Android via Bluetooth?

  21. 21

    从iOS在后台扫描Bluetooth LE设备

  22. 22

    具有iOS ExternalAccessoryFramework的Bluetooth Classic

  23. 23

    iOS:使用NSTimer写入Bluetooth LE设备

  24. 24

    iOS - How To Get Touch Points Correctly?

  25. 25

    "List of devices attached" is empty on Ubuntu 12.04

  26. 26

    How to get a list with the Typesafe config library

  27. 27

    How to get a value from keyvalue pair list?

  28. 28

    How to get file path + file name into a list?

  29. 29

    How to get list of latest tags in remote git?

热门标签

归档