ハロー ブログ

日々のつぶやき @c2c2c2c221

Mac BLE 接続の試行

Mac BLE 接続の試行もできました。

サンプルの「Transferring Data Between Bluetooth Low Energy Devices」からの変更は下記です。

       // Have we received the end-of-message token?
        if stringFromData == "\0EOM" {
            // End-of-message case: show the data.
            // Dispatch the text view update to the main queue for updating the UI, because
            // we don't know which thread this method will be called back on.
            //DispatchQueue.main.async() {
            //    self.textView.text = String(data: self.data, encoding: .utf8)
            //}
            
            // Write test data
            var str:String!
            str = "write data!!!!"
            //let writeData = str.data(using: .utf8)!
            let aa = 0x1b // 音声認識コード
            str = String(aa)
            let writeData = str.data(using: .utf8)!
            
            peripheral.writeValue(writeData, for: transferCharacteristic!, type: .withResponse)