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
API Call Error in Xcode 7/iOS 9 (How to Setup App Transport Security in Plist)
Case Insensitive Matching Search in String Array Swift 3
iOS Swift Streaming App Does Not Play Music in Background Mode
Creating a First Launch Viewcontroller
Uibarbuttonitem Changing Title Not Working
Submit Watchkit Provisioning Error
Trim End Off of String in Swift, Getting Error at Runtime
How to "Rerequest" Email Permission Using Facebook iOS Sdk 4.X
Exceeding Max Text("") Concatenation Length - Swiftui -
Xcode 13 - "Button" Title Not Disappearing
Translate Just 4 Lines of Code from Objective C to Swift (Pointers)
Core Data Nstimeinterval Using an Accessor Directly Is Buggy
Cannot Call Value of Non-Function Type 'Module<Firebase>'
How Has The Nsindexpath Initialization Changed in Swift3
Cannot Subscript a Value of [Anyobject]? with an Index of Type Int
Save Scrollviews Position and Scroll Back to It Later (Offset to Position)