(CoreBluetooth) Код по какой-то причине просто не будет продолжаться - PullRequest
0 голосов
/ 27 апреля 2020

Я просто пришел сюда, чтобы узнать, сможет ли кто-нибудь выяснить, почему мой код просто не работает. В моем V C (ниже) моя вещь не будет go мимо «Подключен к вашему PM5». Я не могу понять, почему, у меня нет никаких ошибок или чего-то подобного? stackoverflow сказал, что мне нужно добавить больше подробностей, чтобы опубликовать это, потому что мой v c слишком длинный, поэтому я просто пишу кучу бесполезного текста на данный момент.

    // If we're powered on, start scanning
    func centralManagerDidUpdateState(_ central: CBCentralManager) {
        print("Central state update")
        if central.state != .poweredOn {
            print("Central is not powered on")
        } else {
            print("Central scanning for", pm5ServiceUUID);
            centralManager.scanForPeripherals(withServices: [pm5ServiceUUID],
                                              options: [CBCentralManagerScanOptionAllowDuplicatesKey : true])
        }
    }
    // Handles the result of the scan
           func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {

               // We've found it so stop scan
               self.centralManager.stopScan()

               // Copy the peripheral instance
               self.peripheral = peripheral
               self.peripheral.delegate = self

               // Connect!
               self.centralManager.connect(self.peripheral, options: nil)

           }
    // The handler if we do connect succesfully
    func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
        if peripheral == self.peripheral {
            print("Connected to your PM5")
            peripheral.discoverServices([pm5ServiceUUID])
        }
    }
    // Handles discovery event
           func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
               if let services = peripheral.services {
                   for service in services {
                       if service.uuid == pm5ServiceUUID {
                           print("LED service found")
                           //Now kick off discovery of characteristics
                           peripheral.discoverCharacteristics([generalStatusUUID, additionalServiceUUID, strokeRateUUID], for: service)
                           return
                       }
                   }
               }
           }
    // Handling discovery of characteristics
           func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
               if let characteristics = service.characteristics {
                   for characteristic in characteristics {
                       if characteristic.uuid == generalStatusUUID {
                           print("General Status found.")
                       } else if characteristic.uuid == additionalServiceUUID {
                           print("Additional Service found.")
                       } else if characteristic.uuid == strokeRateUUID {
                           print("Stroke Rate found");
                       }
                   }
               }
           }


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        centralManager = CBCentralManager(delegate: self, queue: nil)
    }


}

Любая помощь будет оценили. Спасибо!

...