0

I am using SwiftifyBluetooth on Cocoapods but... I did use discoverServices but it only showed as its CBService's value... but I can't seem to know how to convert from its value to string... I checked on how SwiftifyBluetooth and Core Bluetooth work and hit a dead end from myself...

here is the code:

peri[0].discoverServices(withUUIDs: nil, completion: {
                result in
                switch result{
                    
                case .success(let services):
                    print(services)
                    break
                case .failure(let error):
                    print(error)
                    break
                }
            })

and this was the outputted printed in the services EDIT: [<CBService: 0x283f14ac0, isPrimary = YES, UUID = 1804>, <CBService: 0x283f14700, isPrimary = YES, UUID = Battery>, <CBService: 0x283f15480, isPrimary = YES, UUID = Device Information>, <CBService: 0x283f15840, isPrimary = YES, UUID = 49535343-FE7D-4AE5-8FA9-9FAFD205E455>]

I was just checking if this is possible to convert the the CBServices value from that datatype to string

17
  • Try service.uuid.uuidString . Commented Oct 11, 2022 at 7:29
  • @Yonat it doesn't have the scope for that... Commented Oct 12, 2022 at 0:24
  • What do you mean? What happens if you print services.first?.uuid.uuidString? Commented Oct 12, 2022 at 17:46
  • it printed as nil Commented Oct 13, 2022 at 2:20
  • Is services an array? Or a single CBService? Each CBService has a uuid, and the uuid.uuidString is the string ID for that service. Commented Oct 14, 2022 at 6:12

1 Answer 1

0

So I did found a way after I to discover the characteristics put the "180A" in the service UUID to get the Device info as said to the cheat sheet I found about Bluetooth BLE but now my concern why is it showing values as "(null)"

Code after Discovering Services and the Characteristics

periphers[indexing].discoverServices(completion: {
            result in
            switch result{
            case .success(let service):
                print(service)
                break
            case .failure(_):
                break
                }
        })
        
        periphers[indexing].discoverCharacteristics(ofServiceWithUUID: "180A", completion: {
            result in
            switch result{
                case .success(let service):
                    print(service)
                case .failure(let error):
                    print(error)
                    break
            }
        })

output: Output of Characteristics value being null

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.