How to Get MAC Address from Cbperipheral and Cbcenter

How to get Mac Address From CBPeripheral And CBCenter

You can't get the MAC address for a CBPeripheral but you can get the identifier property, which is a UUID that iOS computes from the MAC amongst other information.

This value can be safely stored and used to identify the same peripheral in the future on this particular iOS device.

It cannot be used on another iOS device to identify the same peripheral.

Are CBCentral and CBPeripheral identifiers the same for one device

There's no official statement but experience shows that a remote device is identified by a single UUID. That is, the CBPeripheral and the CBCentral corresponding to the same remote device will have the same UUID. However, these values will be different on each host. E.g. an iPhone will never have the same UUID on different iOS devices that discover it.

Swift 4 save CBPeripherals array save state when returning to controller

Just keep your devices list in the AppDelegate

then access it using something like

let appDelegate = UIApplication.shared.delegate as! AppDelegate
let aVariable = appDelegate.someVariable

Although there is a lot of discussion on whether to use App Delegate as A singleton for storing your objects.
IMHO storing an array of objects that's small won't harm your app anyway

iOS BluetoothLE: CBCentralManager Unsubscribes From Updates

Okay, for heaven's sake. The issue was the line peripheralController.readValue(for: service.characteristics!.first!) I had that line in the app based on some sample code and, well, it was unnecessary.

Apparently the call to readValue(for:) causes some sort of timeout. I edited that line out of the app and it happily updates on and on.

Leaving the question up and adding this answer in case anyone ends up facing the same thing someday.

CBPeripheralManager connection callback

You should make Device A (the presenter) the peripheral, advertising the service, and Device B (the viewers) the central, which subscribes to the peripheral's service.

You can use the CBPeripheralManagerDelegate to get notifications when a central has connected to your peripheral. Here's the documentation of the CBPeripheralManager delegate methods: CBPeripheralManagerDelegate Protocol Reference

This is the method you need to implement to recognize when a central (Device B, a viewer) has connected to your peripheral (Device A, the presenter):

- (void)peripheralManager:(CBPeripheralManager *)peripheral central:(CBCentral *)central didSubscribeToCharacteristic:(CBCharacteristic *)characteristic

This is the method you need to recognize when a central (Device B, a viewer) has disconnected from your peripheral (Device A, the presenter):

- (void)peripheralManager:(CBPeripheralManager *)peripheral central:(CBCentral *)central didUnsubscribeFromCharacteristic:(CBCharacteristic *)characteristic

When you need to notify the subscribed centrals (Device B, the viewers) that the slide has changed, use this method (newValue would be some kind of indicator of the updated position in the presentation, like slide number):

[self.peripheralManager updateValue:newValue forCharacteristic:yourCharacteristic onSubscribedCentrals:nil];

If you want to look through a simple demo of Bluetooth LE sharing with devices acting as both centrals and peripherals, you can check out this project: SimpleShare

Hope that helps! Let me know if I can clarify something.

Laura



Related Topics



Leave a reply



Submit