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

How to get a list with the Typesafe config library

来自分类Dev

Transfer data between iOS and Android via Bluetooth?

来自分类Dev

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

来自分类Dev

How to present list of names in Presenter?

来自分类Dev

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

来自分类Dev

How to get list of latest tags in remote git?

来自分类Dev

"List of devices attached" is empty on Ubuntu 12.04

来自分类Dev

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

来自分类Dev

无法注册Windows.Devices.Bluetooth

来自分类Dev

How to get all available models in Magento?

来自分类Dev

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

来自分类Dev

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

来自分类Dev

从iOS在后台扫描Bluetooth LE设备

来自分类Dev

How to get the deltas of a list collection

来自分类Dev

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

来自分类Dev

具有iOS ExternalAccessoryFramework的Bluetooth Classic

来自分类Dev

Connecting multiple wireless devices to one main device using bluetooth

来自分类Dev

How to get a value from keyvalue pair list?

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

iOS - How To Get Touch Points Correctly?

来自分类Dev

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

来自分类Dev

Windows.Devices.Bluetooth.dll

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

iOS:使用NSTimer写入Bluetooth LE设备

来自分类Dev

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

Related 相关文章

  1. 1

    How to get a list with the Typesafe config library

  2. 2

    Transfer data between iOS and Android via Bluetooth?

  3. 3

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

  4. 4

    How to present list of names in Presenter?

  5. 5

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

  6. 6

    How to get list of latest tags in remote git?

  7. 7

    "List of devices attached" is empty on Ubuntu 12.04

  8. 8

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

  9. 9

    无法注册Windows.Devices.Bluetooth

  10. 10

    How to get all available models in Magento?

  11. 11

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

  12. 12

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

  13. 13

    从iOS在后台扫描Bluetooth LE设备

  14. 14

    How to get the deltas of a list collection

  15. 15

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

  16. 16

    具有iOS ExternalAccessoryFramework的Bluetooth Classic

  17. 17

    Connecting multiple wireless devices to one main device using bluetooth

  18. 18

    How to get a value from keyvalue pair list?

  19. 19

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

  20. 20

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

  21. 21

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

  22. 22

    iOS - How To Get Touch Points Correctly?

  23. 23

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

  24. 24

    Windows.Devices.Bluetooth.dll

  25. 25

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

  26. 26

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

  27. 27

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

  28. 28

    iOS:使用NSTimer写入Bluetooth LE设备

  29. 29

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

热门标签

归档