### Install CoreBluetoothMock with Carthage Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/README.md Specify the CoreBluetoothMock repository in your Cartfile and run 'carthage update'. Copy the framework to your project. ```plaintext github "https://github.com/nordicsemi/IOS-CoreBluetooth-Mock" ~> x.y // Replace x.y with your required version ``` ```bash carthage update --platform iOS // also supported are tvOS, watchOS and macOS ``` -------------------------------- ### Install CoreBluetoothMock with CocoaPods Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/README.md Add the CoreBluetoothMock pod to your Podfile and run 'pod install'. Ensure you open the generated .xcworkspace file. ```ruby target 'YourAppTargetName' do pod 'CoreBluetoothMock' end ``` ```bash pod install ``` -------------------------------- ### Simulate Advertisement Change Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Simulation.md Simulates a change in a peripheral's advertisement data. The peripheral stops advertising with old data and starts with new data. ```swift CBMPeripheralSpec/simulateAdvertisementChange(_:) ``` -------------------------------- ### Simulate Power On Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Simulation.md Turns on the mock central manager. ```swift CBMCentralManagerMock/simulatePowerOn() ``` -------------------------------- ### Initialization Methods Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMCentralManagerDelegate.md Callbacks related to the initialization and state restoration of the central manager. ```APIDOC ## CBMCentralManagerDelegate Initialization ### Description Methods related to the initialization and state restoration of the central manager. ### Methods - `centralManagerDidUpdateState(_:)` - `centralManager(_:willRestoreState:)` - `centralManager(_:didUpdateANCSAuthorizationFor:)` ``` -------------------------------- ### Instantiate CBCentralManager (After) Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Migration guide.md Demonstrates how to instantiate a CBMCentralManager using the factory method, with an option to force mock mode. ```swift let centralManager = CBCentralManagerFactory.instance(delegate: self, queue: .main, forceMock: false) ``` -------------------------------- ### Instantiate CBCentralManager (Before) Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Migration guide.md Shows the original CoreBluetooth way of initializing a CBCentralManager. ```swift let centralManager = CBCentralManager(delegate: self, queue: .main) ``` -------------------------------- ### Simulate Peripherals Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Simulation.md Creates a simulation with a given list of mock peripherals. This should be called when the manager is powered off or before initialization. ```swift CBMCentralManagerMock/simulatePeripherals(_:) ``` -------------------------------- ### Connection Methods Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMCentralManagerDelegate.md Callbacks for connection events with peripherals. ```APIDOC ## CBMCentralManagerDelegate Connection Events ### Description Callbacks for connection events with peripherals. ### Methods - `centralManager(_:didConnect:)` - `centralManager(_:didFailToConnect:error:)` - `centralManager(_:didDisconnectPeripheral:error:)` - `centralManager(_:didDisconnectPeripheral:timestamp:isReconnecting:error:)` ``` -------------------------------- ### Simulate Peripheral Connection Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Simulation.md Simulates another app connecting to a peripheral. The peripheral will stop advertising unless configured otherwise. ```swift CBMPeripheralSpec/simulateConnection() ``` -------------------------------- ### Connection Event Registration Methods Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMCentralManagerDelegate.md Callbacks for registering and handling connection events. ```APIDOC ## CBMCentralManagerDelegate Connection Event Registration ### Description Callbacks for registering and handling connection events. ### Methods - `centralManager(_:connectionEventDidOccur:for:)` ``` -------------------------------- ### Initialize CBMCentralManager using Factory Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMCentralManager.md Instantiate a CBMCentralManager using the provided factory. This is the recommended approach for creating manager instances. ```swift let manager = CBMCentralManagerFactory.initiate(delegate: self, queue: ...) ``` -------------------------------- ### Simulate Peripherals with CoreBluetoothMock Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Mocking peripherals.md Add your defined mock peripherals to the simulation using CBMCentralManagerMock.simulatePeripherals. This makes the mock devices discoverable and interactable within your tests. ```swift CBMCentralManagerMock.simulatePeripherals([blinky]) ``` -------------------------------- ### Receiving Connection Events Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMCentralManager.md Methods and options for registering and handling Bluetooth connection events. ```APIDOC ## CBMCentralManager.registerForConnectionEvents(options:) ### Description Registers the central manager to receive specific Bluetooth connection events. ### Method `registerForConnectionEvents(options:)` ### Parameters - **options** (Dictionary?) - A dictionary specifying the connection events to register for. ``` -------------------------------- ### Scanning Methods Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMCentralManagerDelegate.md Callbacks related to discovering peripherals during scanning. ```APIDOC ## CBMCentralManagerDelegate Scanning ### Description Callbacks related to discovering peripherals during scanning. ### Methods - `centralManager(_:didDiscover:advertisementData:rssi:)` ``` -------------------------------- ### Define a Mock Peripheral Specification Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Mocking peripherals.md Use CBMPeripheralSpec.simulatePeripheral to create a builder for a mock peripheral. Configure its advertisement data, advertising interval, and connection parameters. This is useful for setting up test scenarios with specific device characteristics. ```swift let blinky = CBMPeripheralSpec .simulatePeripheral(proximity: .near) .advertising( advertisementData: [ CBMAdvertisementDataLocalNameKey : "nRF Blinky", CBMAdvertisementDataServiceUUIDsKey : [CBMUUID.nordicBlinkyService], CBMAdvertisementDataIsConnectable : true as NSNumber ], withInterval: 0.250) .connectable( name: "nRF Blinky", services: [.blinkyService], delegate: BlinkyCBMPeripheralSpecDelegate(), connectionInterval: 0.045, mtu: 23) .build() ``` -------------------------------- ### Discovering Services Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMPeripheral.md Methods for discovering services and included services on a peripheral. ```APIDOC ## Discovering Services ### Description Methods to discover the services offered by a peripheral and any services included by those services. ### Methods - **discoverServices(_:)** - **Description**: Discovers the services offered by the peripheral. - **Parameters**: - `serviceUUIDs` ([CBUUID]?): An optional array of service UUIDs to discover. If nil, all services are discovered. - **discoverIncludedServices(_:for:)** - **Description**: Discovers the services that are included by a specified service. - **Parameters**: - `includedServiceUUIDs` ([CBUUID]?): An optional array of included service UUIDs to discover. - `service` (CBMService): The service for which to discover included services. ``` -------------------------------- ### CBMCentralManager Initialization Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMCentralManager.md Initializes a CBMCentralManager instance using a factory. Do not use the direct init method. ```APIDOC ## CBMCentralManagerFactory.initiate ### Description Initializes a CoreBluetoothMock central manager instance. It is recommended to use this factory method for creating manager instances. ### Method Factory Method ### Parameters - **delegate** (CBPeripheralManagerDelegate) - The delegate object to receive Bluetooth events. - **queue** (DispatchQueue?) - The dispatch queue on which the delegate methods are called. ### Request Example ```swift let manager = CBMCentralManagerFactory.initiate(delegate: self, queue: nil) ``` ``` -------------------------------- ### Simulate Initial State Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Simulation.md Defines the initial state of the mock central manager. This must be called before any central manager instance is created. Defaults to powered off. ```swift CBMCentralManagerMock/simulateInitialState(_:) ``` -------------------------------- ### Inspecting Feature Support Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMCentralManager.md Checks for support of specific Bluetooth features. ```APIDOC ## CBMCentralManager.supports(_:) ### Description Checks if the system supports a specific Bluetooth feature. ### Method `supports(_:)` ### Parameters - **feature** (CBMCentralManager.Feature) - The feature to check for support. ``` -------------------------------- ### Simulate Peripheral Reset Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Simulation.md Simulates a hard reset of a peripheral. The central manager will be notified after a delay. ```swift CBMPeripheralSpec/simulateReset() ``` -------------------------------- ### Establishing or Canceling Connections with Peripherals Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMCentralManager.md Methods for establishing and canceling connections to Bluetooth peripherals. ```APIDOC ## CBMCentralManager.connect(_:options:) ### Description Attempts to establish a connection to a peripheral. ### Method `connect(_:options:)` ### Parameters - **peripheral** (CBPeripheral) - The peripheral to connect to. - **options** (Dictionary?) - A dictionary to specify connection options. ``` ```APIDOC ## CBMCentralManager.cancelPeripheralConnection(_:) ### Description Cancels an existing connection to a peripheral. ### Method `cancelPeripheralConnection(_:)` ### Parameters - **peripheral** (CBPeripheral) - The peripheral whose connection should be canceled. ``` -------------------------------- ### Discovering Characteristics and Descriptors Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMPeripheral.md Methods for discovering characteristics and descriptors on a peripheral. ```APIDOC ## Discovering Characteristics and Descriptors ### Description Methods to discover the characteristics of a service and the descriptors for a characteristic. ### Methods - **discoverCharacteristics(_:for:)** - **Description**: Discovers the characteristics of a specified service. - **Parameters**: - `characteristicUUIDs` ([CBUUID]?): An optional array of characteristic UUIDs to discover. - `service` (CBMService): The service for which to discover characteristics. - **discoverDescriptors(for:)** - **Description**: Discovers the descriptors for a specified characteristic. - **Parameters**: - `characteristic` (CBMCharacteristic): The characteristic for which to discover descriptors. ``` -------------------------------- ### Simulate Power Off Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Simulation.md Turns off the mock central manager. All scans and connections will be terminated. ```swift CBMCentralManagerMock/simulatePowerOff() ``` -------------------------------- ### Simulate Peripheral Disconnection Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Simulation.md Simulates a connection error with a peripheral. ```swift CBMPeripheralSpec/simulateDisconnection(withError:) ``` -------------------------------- ### Compare CBMPeripheral instances (After) Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Migration guide.md Shows the correct method for comparing CBMPeripheral objects by their identifiers. ```swift peripheral.identifier == otherPeripheral.identifier ``` -------------------------------- ### Retrieving Lists of Peripherals Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMCentralManager.md Methods for retrieving lists of connected or known peripherals. ```APIDOC ## CBMCentralManager.retrieveConnectedPeripherals(withServices:) ### Description Retrieves a list of peripherals that are currently connected to the system and are advertising specified services. ### Method `retrieveConnectedPeripherals(withServices:)` ### Parameters - **services** ([CBUUID]) - An array of CBUUID objects representing the services to filter by. ``` ```APIDOC ## CBMCentralManager.retrievePeripherals(withIdentifiers:) ### Description Retrieves a list of peripherals that have been previously seen by the system, identified by their UUIDs. ### Method `retrievePeripherals(withIdentifiers:)` ### Parameters - **identifiers** ([UUID]) - An array of UUID objects representing the peripherals to retrieve. ``` -------------------------------- ### Simulate Features Support Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Simulation.md Emulates Bluetooth features supported by the manager. Available on iOS 13+, tvOS 13+, or watchOS 6+. ```swift CBMCentralManagerMock/simulateFeaturesSupport ``` -------------------------------- ### Simulate Peripheral Caching Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Simulation.md Simulates caching a device by the iDevice, making it retrievable by its identifier. Devices are also cached upon scanning. ```swift CBMPeripheralSpec/simulateCaching() ``` -------------------------------- ### Simulate Authorization Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Simulation.md Simulates the authorization state of a Core Bluetooth manager. Non-'.allowedAlways' values change the manager state to unauthorized. ```swift CBMCentralManagerMock/simulateAuthorization(_:) ``` -------------------------------- ### Monitoring a Peripheral’s Connection State Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMPeripheral.md Properties for monitoring the connection state of a peripheral. ```APIDOC ## Monitoring a Peripheral’s Connection State ### Description Provides information about the current connection state of the peripheral and its ability to send data. ### Properties - **state** (CBMPeripheralState) - The current connection state of the peripheral. - **canSendWriteWithoutResponse** (Bool) - A boolean indicating whether the peripheral can send data using write without response. ``` -------------------------------- ### Simulate State Restoration Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Simulation.md Provides a map for state restoration when initializing a central manager with a restore identifier. This map is passed to the delegate's willRestoreState callback. ```swift CBMCentralManagerMock/simulateStateRestoration ``` -------------------------------- ### Compare CBMPeripheral instances (Before) Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Migration guide.md Illustrates the incorrect way to compare CBMPeripheral objects using the equality operator. ```swift peripheral == otherPeripheral ``` -------------------------------- ### Simulate Peripheral Value Update Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Simulation.md Simulates sending a notification or indication from a peripheral. Subscribed clients are notified after a connection interval. ```swift CBMPeripheralSpec/simulateValueUpdate(_:for:) ``` -------------------------------- ### Simulate MAC Address Change Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Simulation.md Simulates a device changing its MAC address. The iDevice treats it as a new device with no cached information. ```swift CBMPeripheralSpec/simulateMacChange(_:) ``` -------------------------------- ### Monitoring Properties Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMCentralManager.md Properties for monitoring the state and delegate of the central manager. ```APIDOC ## CBMCentralManager.delegate ### Description The delegate object that receives updates from the central manager. ### Property `delegate` (CBPeripheralManagerDelegate) ``` ```APIDOC ## CBMCentralManager.state ### Description The current state of the central manager. ### Property `state` (CBManagerState) ``` -------------------------------- ### CBMPeripheral Properties Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMPeripheral.md Properties for identifying a peripheral, accessing its delegate, and retrieving discovered services. ```APIDOC ## CBMPeripheral Properties ### Description Provides access to a peripheral's identifier, name, delegate, and discovered services. ### Properties - **identifier** (UUID) - The unique identifier for the peripheral. - **name** (String?) - The name of the peripheral. - **delegate** (CBMPeripheralDelegate?) - The delegate object that will receive peripheral events. - **services** (Array?) - An array of discovered services offered by the peripheral. ``` -------------------------------- ### Simulate Peripheral Proximity Change Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Simulation.md Simulates a peripheral moving closer to or further away from the device. ```swift CBMPeripheralSpec/simulateProximityChange(_:) ``` -------------------------------- ### Add CoreBluetoothMock Dependency with Swift Package Manager Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/README.md Include the CoreBluetoothMock package in your Swift.package file and add it to your target's dependencies. ```swift dependencies: [ // [...] .package(name: "CoreBluetoothMock", url: "https://github.com/nordicsemi/IOS-CoreBluetooth-Mock.git", .upToNextMajor(from: "x.y")) // Replace x.y with your required version ] ``` ```swift targets: [ // [...] .target( name: "", dependencies: ["CoreBluetoothMock"]) ] ``` -------------------------------- ### Reading Characteristic and Descriptor Values Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMPeripheral.md Methods for reading the values of characteristics and descriptors. ```APIDOC ## Reading Characteristic and Descriptor Values ### Description Methods to asynchronously read the value of a characteristic or a descriptor. ### Methods - **readValue(for:)** - **Description**: Reads the value of a specified characteristic. - **Parameters**: - `characteristic` (CBMCharacteristic): The characteristic whose value is to be read. - **readValue(for:)** - **Description**: Reads the value of a specified descriptor. - **Parameters**: - `descriptor` (CBMDescriptor): The descriptor whose value is to be read. ``` -------------------------------- ### Writing Characteristic and Descriptor Values Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMPeripheral.md Methods for writing values to characteristics and descriptors, and determining maximum write lengths. ```APIDOC ## Writing Characteristic and Descriptor Values ### Description Methods for writing data to a characteristic or descriptor, and for determining the maximum data length for writes. ### Methods - **writeValue(_:for:type:)** - **Description**: Writes a value to a characteristic with a specified write type. - **Parameters**: - `data` (Data): The data to write. - `characteristic` (CBMCharacteristic): The characteristic to write to. - `type` (CBMCharacteristicWriteType): The type of write operation. - **writeValue(_:for:)** - **Description**: Writes a value to a characteristic using the default write type. - **Parameters**: - `data` (Data): The data to write. - `characteristic` (CBMCharacteristic): The characteristic to write to. - **maximumWriteValueLength(for:)** - **Description**: Returns the maximum length of data that can be sent in a single write operation for a given characteristic write type. - **Parameters**: - `type` (CBMCharacteristicWriteType): The type of write operation. ``` -------------------------------- ### Tear Down Simulation Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/Simulation.md Resets all central managers to an unknown state and clears mock data, returning the mock manager to its initial state. ```swift CBMCentralManagerMock/tearDownSimulation() ``` -------------------------------- ### Scanning or Stopping Scans of Peripherals Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMCentralManager.md Methods for initiating and stopping the scanning process for nearby Bluetooth peripherals. ```APIDOC ## CBMCentralManager.scanForPeripherals(withServices:options:) ### Description Begins scanning for Bluetooth peripherals that are advertising. ### Method `scanForPeripherals(withServices:options:)` ### Parameters - **services** ([CBUUID]?) - An optional array of CBUUID objects to filter the scan results by service. - **options** (Dictionary?) - A dictionary to specify scan options. ``` ```APIDOC ## CBMCentralManager.stopScan() ### Description Stops the Bluetooth peripheral scanning process. ### Method `stopScan()` ``` ```APIDOC ## CBMCentralManager.isScanning ### Description A boolean value indicating whether the central manager is currently scanning for peripherals. ### Property `isScanning` (Bool) ``` -------------------------------- ### Accessing a Peripheral’s Signal Strength Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMPeripheral.md Method for reading the Received Signal Strength Indicator (RSSI) of a peripheral. ```APIDOC ## Accessing a Peripheral’s Signal Strength ### Description Asynchronously reads the current RSSI for a peripheral. ### Method - **readRSSI()** - **Description**: Reads the RSSI of the peripheral. ``` -------------------------------- ### Working with Apple Notification Center Service (ANCS) Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMPeripheral.md Property to check ANCS authorization status. ```APIDOC ## Working with Apple Notification Center Service (ANCS) ### Description Provides information about the authorization status for the Apple Notification Center Service. ### Property - **ancsAuthorized** (Bool) - A boolean indicating whether the peripheral is authorized for ANCS. ``` -------------------------------- ### Setting Notifications for a Characteristic’s Value Source: https://github.com/nordicsemi/ios-corebluetooth-mock/blob/main/CoreBluetoothMock/Documentation.docc/CBMPeripheral.md Method to enable or disable notifications for a characteristic's value. ```APIDOC ## Setting Notifications for a Characteristic’s Value ### Description Enables or disables notifications for updates to a characteristic's value. ### Method - **setNotifyValue(_:for:)** - **Description**: Enables or disables notifications for the specified characteristic. - **Parameters**: - `enabled` (Bool): `true` to enable notifications, `false` to disable. - `characteristic` (CBMCharacteristic): The characteristic for which to set notification state. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.