Связь с HM10 от iphone swift xcode

Я хочу общаться с моим HM10 через приложение iPhone, я уже создал приложение для установления соединения с HM10, я могу отправлять данные на Bluetooth, но я не получаю данные, ниже приведен код:-

Это ничего не печатает.

 func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
    // notify the delegate in different ways
    // if you don't use one of these, just comment it (for optimum efficiency :])
    let data = characteristic.value
    guard data != nil else { return }

    // first the data
    delegate.serialDidReceiveData(data!)
  //  print(data)

    // then the string
    if let str = String(data: data!, encoding: String.Encoding.utf8) {
        delegate.serialDidReceiveString(str)
        print("str")
    } else {
        //print("Received an invalid string!") uncomment for debugging
    }

    // now the bytes array
    var bytes = [UInt8](repeating: 0, count: data!.count / MemoryLayout<UInt8>.size)
    (data! as NSData).getBytes(&bytes, length: data!.count)
    delegate.serialDidReceiveBytes(bytes)
    print(bytes)
//    print(delegate.serialDidReceiveData(bytes))
}
func serialDidReceiveString(message: String) {
   // Label.text! = message
    print(message)

0 ответов

Другие вопросы по тегам