This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Swift 3 - CBPeripheral.services nil problem

Hi, I was trying to create an NUS (Nordic UART Service) application for iOS 10 devices using Swift 3.

I was testing with my

  • iPhone 6 Plus 64GB (iOS 10.2.1)

  • PCA10040 v1.1 that has NUS peripheral example from SDK 12.1 + S132 v3.0

ViewController.swift

As you see my attachment, I left a comment at the centralManager function.

When the centralManagerfunction is called, the log screen printed Nordic_UART.

However, the services couldn't be printed because it was nil.

Are there extra configurations to set in order to get the services?

-Best Regards

Parents
  • You are on the right track, but you are still missing the service and characteristic discovery steps.

    When you connect to a peripheral, you should call discoverServices, and when you get the callback to didDiscoverServices, the services property of your CBPeripheral will be populated.

    Afterwards, you should discover characteristics for each service using the discoverCharacteristics method, you will then get a callback to didDiscoverCharacteristics, at this point, your CBPeriphreal will include all the Services/Characteristics. without those steps, it'll all remain Nil.

    Tips: You should specify the services you're interested in discovering, leaving this filter Nil will work, but is discouraged by Apple.

    And here is the code that can walk you through how the nRFToolbox app does it

  • No, those are the characteristics, you should scan only for the service first, using that UUID:

    `6E400001-B5A3-F393-E0A9-E50E24DCCA9E` //UART Service
    

    After that service is discovered, you should discover characteristics for this service, you may use a nil filter to discover all, or specify only the RX/TX characteristic UUIDs like so:

    `6E400002-B5A3-F393-E0A9-E50E24DCCA9E` //RX Characteristic
    `6E400003-B5A3-F393-E0A9-E50E24DCCA9E` //TX Characteristic
    

    after those are discovered, you may proceed to write/read form those characteristics.

Reply
  • No, those are the characteristics, you should scan only for the service first, using that UUID:

    `6E400001-B5A3-F393-E0A9-E50E24DCCA9E` //UART Service
    

    After that service is discovered, you should discover characteristics for this service, you may use a nil filter to discover all, or specify only the RX/TX characteristic UUIDs like so:

    `6E400002-B5A3-F393-E0A9-E50E24DCCA9E` //RX Characteristic
    `6E400003-B5A3-F393-E0A9-E50E24DCCA9E` //TX Characteristic
    

    after those are discovered, you may proceed to write/read form those characteristics.

Children
No Data
Related