Ситуация такая, что никак не могу понять, почему мое приложение и приложения которые находил на github не видят мое устройство, но приложение BlueCap видит и все с ним отлично, а когда пытаюсь использовать этот фреймворк ничего не выходит, уже и примеры находил в статьях где люди использовали этот фреймворк но их приложения так же не видит мое устройство.Ниже мой код без фреймворков
class ViewController: UIViewController, CBCentralManagerDelegate, CBPeripheralManagerDelegate {
var manager: CBCentralManager!
var peripheral: CBPeripheral!
let NAME_OF_DEVICE = "NAME"
let READ_FROM_DEVICE_SERVICE = CBUUID(string:“0000ffe0-0000-1000-8000-00805f9b34fb”)
let READ_FROM_DEVICE_CHARACTERISTIC = CBUUID(string: “0000ffe4-0000-1000-8000-00805f9b34fb”)
let WRITE_TO_DEVICE_SERVICE = CBUUID(string:“0000ffe5-0000-1000-8000-00805f9b34fb”)
let WRITE_TO_DEVICE_CHARACTERISTIC = CBUUID(string:“0000ffe9-0000-1000-8000-00805f9b34fb”)
let CLIENT_CHARACTERISTIC_CONFIG = CBUUID(string:“00002902-0000-1000-8000-00805f9b34fb”)
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
manager = CBCentralManager(delegate: self, queue: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {
return
}
func centralManagerDidUpdateState(_ central:CBCentralManager) {
if central.state == .poweredOn {
central.scanForPeripherals(withServices:nil, options: [CBCentralManagerScanOptionAllowDuplicatesKey : true])
print(central)
} else {
print("Bluetoolth not avalible")
}
}
private func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject],RSSI: NSNumber) {
print("hi")
let device = (advertisementData as NSDictionary)
.object(forKey: CBAdvertisementDataLocalNameKey) as? NSString
print("\(device)")
if device?.contains(NAME_OF_DEVICE) == true {
self.manager.stopScan()
print(manager)
self.peripheral = peripheral
self.peripheral.delegate = peripheral.delegate
print("\(device)")
manager.connect(peripheral, options: nil)
print("\(device)")
}
print("\(device)")
}
func centralManager(central: CBCentralManager, didConnectPeripheral peripheral: CBPeripheral){
peripheral.discoverServices(nil)
self.manager.stopScan()
}
func perepheral(central: CBCentralManager, didDiscoverServices error: NSError?){
for service in peripheral.services! {
let thisService = service as CBService
if service.uuid == READ_FROM_DEVICE_SERVICE {
peripheral.discoverCharacteristics(nil, for: thisService)
}
print(service)
}
print(perepheral)
}
func peripheral(peripheral:CBPeripheral,didDiscoverCharacteristicsForService service: CBService, error: NSError?){
for characteristic in service.characteristics!{
let thisCharacteristics = characteristic as CBCharacteristic
if thisCharacteristics.uuid == WRITE_TO_DEVICE_SERVICE{
self.peripheral.setNotifyValue(true,for: thisCharacteristics )
}
print(thisCharacteristics)
}
}
func peripheral(peripheral:CBPeripheral, didUpdateValueForCharacteristic characteristic:CBCharacteristic, error: NSError?){
var count:UInt8 = 0;
if characteristic.uuid == READ_FROM_DEVICE_SERVICE {
characteristic.value!.copyBytes(to: &count, count: characteristic.value!.count)
print(characteristic)
}
print(characteristic)
print(error!)
}
func centralManager(_ central: CBCentralManager,didDisconnectPeripheral peripheral: CBPeripheral,error: Error?) {
central.scanForPeripherals(withServices: nil, options: nil)
}