11. CR2032
225 mAh
Data Transaction Time
3s
Max Antenna Power
15 mA
225 mAh / 15mA = 15 hours
15 hours = 54,000,000 ms
54M ms / 3 ms = 18M transactions
1 transaction every second = ~7 months
Monday, November 18, 13
31. [centralManager scanForPeripheralsWithServices:serviceUUIDs options:options];
Core Bluetooth
peripheral
Bluetooth Device Address
00:22:D0:00:AC:92
BDA
NSUUID
Your App
(NSUUID *) peripheral.identifier =
68753A44-4D6F-1226-9C60-0050E4C00067
// CBCentralManagerDelegate
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral
advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
// peripheral.services is empty until you call [peripheral discoverServices:];
NSArray *serviceUUIDs = [advertismentData objectForKey: CBAdvertisementDataServiceUUIDsKey];
}
Monday, November 18, 13
32. (NSDictionary *)advertisementData
CBAdvertisementDataLocalNameKey
Name of Device
CBAdvertisementDataManufacturerDataKey
ID for Manufacturer
CBAdvertisementDataServiceDataKey
Dictionary with serviceUUIDs and data
CBAdvertisementDataServiceUUIDsKey
Array of serviceUUIDs
CBAdvertisementDataTxPowerLevelKey
Power Level of Transmission (optional)
CBAdvertisementDataIsConnectable
If Device data is connectable
Monday, November 18, 13
34. // Check Peripherals That Your App Has Connected To Before
- (NSArray *)retrievePeripheralsWithIdentifiers:(NSArray *)identifiers
// Check Peripherals Already Connected To iPhone
// Peripherals may be connected to other apps, but not yours
- (NSArray *)retrieveConnectedPeripheralsWithServices:(NSArray *)serviceUUIDs
// Scan For New Peripherals
- (void)scanForPeripheralsWithServices:(NSArray *)serviceUUIDs options:(NSDictionary *)options
// Callback in CBCentralManagerDelegate
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral
advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
-connectPeripheral:options:
Monday, November 18, 13
35. CBCentralManager
Scan for all peripherals
Foreground
Can have multiple peripheral
discoveries
Scan frequency normal
CBPeripheralManager
Service UUIDs are advertised
Device Name advertised
Advertising frequency highest
Can only scan for service UUID
Monday, November 18, 13
Peripheral discovered only once
Device Name is hidden
Scan frequency 55x less
Background
ServiceUUIDs are hidden
Advertising frequency decreased
36. Reconnecting Peripheral
Foreground
Active - Visible
Background
Active - Not Visible
Suspended
Inactive - In Memory
Terminated
Not in Memory
Monday, November 18, 13
// CBCentralMangerDelegateProtocol
- centralManager:central didDisconnectPeripheral:peripheral error:error
{
if (error) {
// User did not cancel connection. Reconnect.
// Connection Requests DO NOT TIME OUT
[central connectPeripheral:peripheral options:nil];
}
}
// CBCentralMangerDelegateProtocol
- centralManager:central didConnectPeripheral:peripheral
{
// App will be brought back to background state
}
State Preservation and Restore
37. Scanning For Peripherals
Foreground
Active - Visible
Background
Active - Not Visible
Suspended
Inactive - In Memory
Terminated
Not in Memory
Monday, November 18, 13
// CBCentralMangerDelegateProtocol
- (void)centralManager:(CBCentralManager *)central
didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:
(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
// Device can connect to BLE Peripheral and run task
// In Background, you have 10s to complete task.
// Background scanning also runs 55X slower or more.
}
Scanning is not possible
iOS cannot guarantee that you will not be
suspended or that you will be brought back to
background once suspended.
38. Your
App
Monday, November 18, 13
If the user removes your app
in the multi-tasking window,
then all your background
operations stop.