Bluetooth Didconnect or Didfailtoconnect Not Called Xcode 9.2 with iOS 11.1.2

Bluetooth Peripheral Stuck in Connecting State On iOS

You don't want that while loop; This will just block the Core Bluetooth delegate thread. After issuing the connect you will get a call to the didConnect CBCentralManagerDelegate method. Once the peripheral is connected you need to call discoverServices on the peripheral, which will give a callback to the peripheral:didDiscoverServices: peripheral delegate method. You can then discover the characteristics in a similar way.

func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
// get advertisement data and check to make sure the name is matching. set it as the peripheral then make connection
if let peripheralName = advertisementData[CBAdvertisementDataLocalNameKey] as? String {
print("NEXT PERIPHERAL NAME: \(peripheralName)")
print("NEXT PERIPHERAL UUID: \(peripheral.identifier.uuidString)")

if peripheralName == nameID {
self.peripheralHalo = peripheral
central.stopScan()
central.connect(peripheral, options: nil)
}
}
}

func centralManager(_ central: CBCentralManager,
didConnect peripheral: CBPeripheral) {
print("Connected!!")
peripheralHalo!.delegate = self
peripheral.discoverServices([serviceID)
}

Also, if you are going to store something that identifies which peripheral you want to connect to, I suggest you use the identifier and not the name as the name can change.

MySQL query: work out the average rating for each user then order the results by average rating and number of ratings

If you group and count, you need having:

SELECT username, (SUM(rating)/COUNT(*)) as TheAverage, Count(*) as TheCount
FROM rating
WHERE month='Aug'
GROUP BY username
HAVING TheCount > 1
ORDER BY TheAverage DESC, TheCount DESC

How to delete file after end of streaming wcf

I found great solution in this blog if someone will need it in the future

OperationContext clientContext = OperationContext.Current;
clientContext.OperationCompleted += new EventHandler(delegate(object sender, EventArgs args)
{
if (fileStream != null)
fileStream.Dispose();
});


Related Topics



Leave a reply



Submit