Bluetooth App built in UIKIT is unable to read data from connected peripheral but it equivalent in swiftui works fine.

I am developing an ios Bluetooth app with Swift and UIKIT, The app scans for a specific Bluetooth service and connects to it. Once the connection is established, I discover the services and characteristics of the connected peripheral. The peripheral has two characteristics. One for writing to the peripheral and the other for notifying and reading data from the device.

Writing to the peripheral works fine but reading from the device gives the error shown below. Error Domain=CBATTErrorDomain Code=2 "Reading is not permitted." UserInfo={NSLocalizedDescription=Reading is not permitted.}

But I have the same app developed in swift and SwiftUI and both writing and reading work fine with the same peripheral connected.

Can anyone please explain to me why this is happening? Thank you

UIKit and SwiftUI both are UI frameworks and are both unrelated to the bluetooth APIs. It seems that you have a difference in your code elsewhere that is causing this issue.

Bluetooth App built in UIKIT is unable to read data from connected peripheral but it equivalent in swiftui works fine.
 
 
Q