Mac Developer Library

Developer

Core Bluetooth Framework Reference CBCentralManagerDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

CBCentralManagerDelegate

The CBCentralManagerDelegate protocol defines the methods that a delegate of a CBCentralManager object must adopt. The optional methods of the protocol allow the delegate to monitor the discovery, connectivity, and retrieval of peripheral devices. The only required method of the protocol indicates the availability of the central manager, and is called when the central manager’s state is updated.

  • Invoked when the central manager’s state is updated.

    Declaration

    Swift

    func centralManagerDidUpdateState(_ central: CBCentralManager)

    Objective-C

    - (void)centralManagerDidUpdateState:(CBCentralManager *)central

    Parameters

    central

    The central manager whose state has changed.

    Discussion

    You implement this required method to ensure that Bluetooth low energy is supported and available to use on the central device. You should issue commands to the central manager only when the state of the central manager is powered on, as indicated by the CBCentralManagerStatePoweredOn constant. A state with a value lower than CBCentralManagerStatePoweredOn implies that scanning has stopped and that any connected peripherals have been disconnected. If the state moves below CBCentralManagerStatePoweredOff, all CBPeripheral objects obtained from this central manager become invalid and must be retrieved or discovered again. For a complete list and discussion of the possible values representing the state of the central manager, see the CBCentralManagerState enumeration in CBCentralManager Class Reference.

    Availability

    Available in OS X v10.7 and later.

  • Invoked when the central manager is about to be restored by the system.

    Declaration

    Swift

    optional func centralManager(_ central: CBCentralManager, willRestoreState dict: [String : AnyObject])

    Objective-C

    - (void)centralManager:(CBCentralManager *)central willRestoreState:(NSDictionary<NSString *,id> *)dict

    Parameters

    central

    The central manager providing this information.

    dict

    A dictionary containing information about the central manager that was preserved by the system at the time the app was terminated. For the available keys to this dictionary, see Central Manager State Restoration Options.

    Discussion

    For apps that opt in to the state preservation and restoration feature of Core Bluetooth, this is the first method invoked when your app is relaunched into the background to complete some Bluetooth-related task. Use this method to synchronize the state of your app with the state of the Bluetooth system.

    Availability

    Available in OS X v10.9 and later.

  • Keys to specify in an advertisementData dictionary.

    Declaration

    Swift

    let CBAdvertisementDataLocalNameKey: String let CBAdvertisementDataManufacturerDataKey: String let CBAdvertisementDataServiceDataKey: String let CBAdvertisementDataServiceUUIDsKey: String let CBAdvertisementDataOverflowServiceUUIDsKey: String let CBAdvertisementDataTxPowerLevelKey: String let CBAdvertisementDataIsConnectable: String let CBAdvertisementDataSolicitedServiceUUIDsKey: String

    Objective-C

    NSString *const CBAdvertisementDataLocalNameKey; NSString *const CBAdvertisementDataManufacturerDataKey; NSString *const CBAdvertisementDataServiceDataKey; NSString *const CBAdvertisementDataServiceUUIDsKey; NSString *const CBAdvertisementDataOverflowServiceUUIDsKey; NSString *const CBAdvertisementDataTxPowerLevelKey; NSString *const CBAdvertisementDataIsConnectable; NSString *const CBAdvertisementDataSolicitedServiceUUIDsKey;

    Constants

    • CBAdvertisementDataLocalNameKey

      CBAdvertisementDataLocalNameKey

      A string (an instance of NSString) containing the local name of a peripheral.

      Available in OS X v10.7 and later.

    • CBAdvertisementDataManufacturerDataKey

      CBAdvertisementDataManufacturerDataKey

      A NSData object containing the manufacturer data of a peripheral.

      Available in OS X v10.7 and later.

    • CBAdvertisementDataServiceDataKey

      CBAdvertisementDataServiceDataKey

      A dictionary containing service-specific advertisement data.

      The keys are CBUUID objects, representing CBService UUIDs. The values are NSData objects, representing service-specific data.

      Available in OS X v10.7 and later.

    • CBAdvertisementDataServiceUUIDsKey

      CBAdvertisementDataServiceUUIDsKey

      An array of service UUIDs.

      Available in OS X v10.7 and later.

    • CBAdvertisementDataOverflowServiceUUIDsKey

      CBAdvertisementDataOverflowServiceUUIDsKey

      An array of one or more CBUUID objects, representing CBService UUIDs that were found in the “overflow” area of the advertisement data.

      Due to the nature of the data stored in this area, UUIDs listed here are “best effort” and may not always be accurate. For details about the overflow area of advertisement data, see the startAdvertising: method in CBPeripheralManager Class Reference.

      Available in OS X v10.9 and later.

    • CBAdvertisementDataTxPowerLevelKey

      CBAdvertisementDataTxPowerLevelKey

      A number (an instance of NSNumber) containing the transmit power of a peripheral.

      This key and value are available if the broadcaster (peripheral) provides its Tx power level in its advertising packet. Using the RSSI value and the Tx power level, it is possible to calculate path loss.

      Available in OS X v10.7 and later.

    • CBAdvertisementDataIsConnectable

      CBAdvertisementDataIsConnectable

      A Boolean value that indicates whether the advertising event type is connectable.

      The value for this key is an NSNumber object. You can use this value to determine whether a peripheral is connectable at a particular moment.

      Available in OS X v10.9 and later.

    • CBAdvertisementDataSolicitedServiceUUIDsKey

      CBAdvertisementDataSolicitedServiceUUIDsKey

      An array of one or more CBUUID objects, representing CBService UUIDs.

      Available in OS X v10.9 and later.