Я получаю каждый раз одну и ту же ошибку: поток 3: сигнал SIGABRT, что я могу сделать? - PullRequest
0 голосов
/ 28 марта 2020
import UIKit
import CoreBluetooth

class ViewController: UIViewController, CBCentralManagerDelegate, CBPeripheralDelegate {
    var centralmanager: CBCentralManager!
    var scale: CBPeripheral?

    let serviceUUID = CBUUID(string: "2A25")
    let nonincharacteristicUUID = CBUUID(string: "2A29")

    @IBOutlet weak var label2: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        centralmanager = CBCentralManager()
        centralmanager.delegate = self
    }
    //Central Manager delegate
    func centralManagerDidUpdateState(_ central: CBCentralManager) {
        if central.state == .poweredOn {
            centralmanager.scanForPeripherals(withServices: [serviceUUID], options: nil)

        }
    }

    func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData advertisemnetData: [String : Any], rssi RSSI: NSNumber) {
        centralmanager.stopScan()
        scale = peripheral
        centralmanager.connect(peripheral, options: nil)
    }

    func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
        peripheral.delegate=self
        peripheral.discoverServices([serviceUUID])
    }


    //Peripheral delegate

    func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
        if let service = peripheral.services?.first(where: {$0.uuid == serviceUUID }) {
            peripheral.discoverCharacteristics([nonincharacteristicUUID],for:service)
        }
    }

    func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
        if let characteristic = service.characteristics?.first(where: { $0.uuid == nonincharacteristicUUID}) {
            peripheral.setNotifyValue(true, for: characteristic)
        }
    }
    //func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
      //  if let data = characteristic.value {
      //      let weight: Int = data.withUnsafeBytes { $0.pointee }
        //    Label1.text = String(weight) + "Hz"
       // }
    //}
    func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
        if let data = characteristic.value {
            let weight: Int = data.withUnsafeBytes { $0.pointee }
            label2.text = String(weight) + "Hz"
        }
    }

}

Я получаю одну и ту же ошибку каждый раз, когда у кого-то появляется идея? Пожалуйста, помогите: (

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...