Domanda

Sono sicuro del 99% ho seguito le istruzioni per impostare correttamente CoreBluetooth.Non importa cosa faccio, quando eseguo questa app sul mio iPad Mini, il Bluetooth sta dicendo il suo.Sta dicendo che sta eseguendo la scansione dei dispositivi, ma non trova assolutamente alcun dispositivo.Se vado al menu Bluetooth sul dispositivo, vedo scoprire altri dispositivi.Inizializza il CBCentralManager.Istando centralManagerDidUpdateState.Quando ciò è sicuro che il Bluetooth è pronto, chiama centralManager.scanForPeripheralsWithServices.Tutto ciò sta accadendo correttamente.Ma la mia funzione delegata centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!) non viene mai chiamata.Il mio codice è molto semplice.Forse mi manca qualcosa ma sono stato in grado di confermare che il mio MacBook è un dispositivo BTLE e il mio iPad Mini è anche un dispositivo BTLE.Ecco il mio codice.

import UIKit
import CoreBluetooth

class ViewController: UIViewController, CBCentralManagerDelegate {

    var centralManager:CBCentralManager!
    var blueToothReady = false

    override func viewDidLoad() {
        super.viewDidLoad()
        startUpCentralManager()
    }

    func startUpCentralManager() {
        println("Initializing central manager")
        centralManager = CBCentralManager(delegate: self, queue: nil)
    }

    func discoverDevices() {
        println("discovering devices")
        centralManager.scanForPeripheralsWithServices(nil, options: nil)
    }

    func centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!) {
        println("Discovered \(peripheral.name)")
    }

    func centralManagerDidUpdateState(central: CBCentralManager!) {
        println("checking state")
        switch (central.state) {
            case .PoweredOff:
            println("CoreBluetooth BLE hardware is powered off")

            case .PoweredOn:
            println("CoreBluetooth BLE hardware is powered on and ready")
            blueToothReady = true;

            case .Resetting:
            println("CoreBluetooth BLE hardware is resetting")

            case .Unauthorized:
            println("CoreBluetooth BLE state is unauthorized")

            case .Unknown:
            println("CoreBluetooth BLE state is unknown");

            case .Unsupported:
            println("CoreBluetooth BLE hardware is unsupported on this platform");

        }
        if blueToothReady {
            discoverDevices()
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
.

È stato utile?

Soluzione

Ho dovuto ottenere la mia pubblicità del mio MacBook.Una volta che usi https://github.com/mttrb/beaconosx ha funzionato esattamente come ho scrittoesso

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top