Использую библиотеку BlueSwift, для работы с BLE.
Cкопировал пример. Не работает. При попытке подключения к устройству - выбрасывает ошибку.
Исходный код:
//
// ViewController.swift
// ESP32_BLE
//
// Created by Victor on 14.11.2019.
// Copyright © 2019 Snufkin52. All rights reserved.
//
import UIKit
import BlueSwift
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
let connection = BluetoothConnection.shared
private var loading = false;
lazy var characteristic = try! Characteristic(uuid: "cc46b944-003e-42b6-b836-c4246b8f19a0", shouldObserveNotification: true)
lazy var service = try! Service(uuid: "9a8ca9ef-e43f-4157-9fee-c37a3d7dc12d", characteristics: [characteristic])
lazy var peripheral: Peripheral<Connectable> = {
let configuration = try! Configuration(services: [service], advertisement: "1004FD87-820F-438A-B757-7AC2C15C2D56")
return Peripheral(configuration: configuration)
}()
@IBAction func connect(_ sender: Any) {
connection.connect(peripheral) { [weak self] _ in
self?.loading = false
}
}
@IBAction func write()
{
let command = Command.utf8String("HELLO")
peripheral.write(command: command, characteristic: characteristic) { error in
print("Did write")
}
}
}