I don't know how to use CoreBluetooth
and I'm trying to find my iPad and get info of gps, accelerometer, gyroscope from that iPad (don't ask why). I know how to get gps location but I don't know how to get accelerometer and gyroscope too. Plz help me.
App must be in swift.
import UIKit
import CoreBluetooth
class ViewController: UIViewController, CBCentralManagerDelegate {
@IBOutlet var initializing: UILabel!
@IBOutlet var disconvering: UILabel!
@IBOutlet var checkingState: UILabel!
@IBOutlet var coreBluetooth: UILabel!
@IBOutlet var discoveredDevices: UILabel!
var centralManager:CBCentralManager!
var blueToothReady = false
override func viewDidLoad() {
super.viewDidLoad()
startUpCentralManager()
}
func startUpCentralManager() {
initializing.text = "Initializing central manager"
centralManager = CBCentralManager(delegate: self, queue: nil)
}
func discoverDevices() {
disconvering.text = "Discovering devices"
centralManager.scanForPeripheralsWithServices(nil, options: nil)
}
func centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!) {
discoveredDevices.text = "Discovered \(peripheral.name)"
}
func centralManagerDidUpdateState(central: CBCentralManager!) {
checkingState.text = "Checking state"
switch (central.state) {
case .PoweredOff:
coreBluetooth.text = "CoreBluetooth BLE hardware is powered off"
case .PoweredOn:
coreBluetooth.text = "CoreBluetooth BLE hardware is powered on and ready"
blueToothReady = true;
case .Resetting:
coreBluetooth.text = "CoreBluetooth BLE hardware is resetting"
case .Unauthorized:
coreBluetooth.text = "CoreBluetooth BLE state is unauthorized"
case .Unknown:
coreBluetooth.text = "CoreBluetooth BLE state is unknown"
case .Unsupported:
coreBluetooth.text = "CoreBluetooth BLE hardware is unsupported on this platform"
}
if blueToothReady {
discoverDevices()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Ok I made virtual Peripheral in LighBlue app and this code works:
This code works with LightBlue app and was converted from CoreBluetooth Objective C Programming guide.