Hello everyone , Lets create application for Bluetooth Low Energy Peripheral in objective C. This application will simply advertise data for BLE Central devices. Create a new Xcode project using the Single-View Application template. Name it BleServer . Once the project is created, add the CoreBluetooth.framework to it. Then, open the ViewController.h file and add the following line:

 #import <CoreBluetooth/CoreBluetooth.h> 

Add CBPeripheralManagerDelegate protocol to the ViewController.

Now create a property of peripheral manager

 @property(nonatomic, strong) CBPeripheralManager *peripheral;

Let us initialize this property in viewDidLoad.

self.peripheral = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];

Passing 'nil' to parameter queue specifies CBPeripheralManager will run on main thread. If you want it to run on other thread , you can create and pass it to the parameter.

Once the Peripheral Manager is initialized, we need to check its state. this ensures that Bluetooth low energy is supported and available to use on the local peripheral device. For this we need to implement below required method of CBPeripheralManagerDelegate.

- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral {
    switch (peripheral.state) {
        case CBPeripheralManagerStatePoweredOn:
            [self setupBLEService];
        case CBManagerStatePoweredOff: {
            [self disableBLEService];
            NSLog(@"Peripheral Manager did change state");
Here, We check the state of the Peripheral Manager. If its state is CBPeripheralManagerStatePoweredOn (or CBManagerStatePoweredOn available on iOS 10.0 and newer), then the device is using Bluetooth LE and we are good to go. We will set up our services and characteristics here. If its state is CBPeripheralManagerStatePoweredOff (or CBManagerStatePoweredOff available on iOS 10.0 and newer), then device not using Bluetooth LE currently or its off. We will disable our services here.

Service and Characteristic : Bluetooth Services and Characteristics are identified using uuid's. You can learn more about BLE services from this link. UUID's are generally 16bit or 128 bit. The advertising packet data length is limited to 31 bytes by the spec. So we will be using 16 bit UUID here. To start with, let us define UUID's service and characteristics respectively. You can change it with the UUID's you wish.

#define ADVERTISING_CHAR_UUID_16 @"b71e"

Lets create properties for service and characteristic

@property(nonatomic, strong) CBMutableCharacteristic *characteristic;
@property(nonatomic, strong) CBMutableService *service;

Now lets write code to set up and disable BLE services ,

- (void)setupBLEService {
    // If the service is already registered, we need to re-register it again.
    if (self.service) {
        [self.peripheral removeService:self.service];
    // Create a BLE Peripheral Service and set it to be the primary. If it
    // is not set to the primary, it will not be found when the app is in the
    // background.
    self.service = [[CBMutableService alloc]
                    initWithType:ADVERTISING_SERVICE_UUID_16 primary:YES];
    // Set up the characteristic in the service. This characteristic is only
    // readable through subscription (CBCharacteristicsPropertyNotify) and has
    // no default value set.
    self.characteristic =
    [[CBMutableCharacteristic alloc]
     properties:CBCharacteristicPropertyNotify | CBCharacteristicPropertyRead
    // Assign the characteristic.
    self.service.characteristics =
    [NSArray arrayWithObject:self.characteristic];
    // Add the service to the peripheral manager.
    [self.peripheral addService:self.service];

- (void)disableService {
    [self.peripheral removeService:self.service];
    self.service = nil;
    [self.peripheral stopAdvertising];

Once we add the service to the Peripheral Manager it notifies its delegate with the method -peripheralManager:didAddService:error:. Here, if there is no error, we can start advertising the service:

 - (void)peripheralManager:(CBPeripheralManager *)peripheral didAddService:(CBService *)service 
error:(NSError *)error {
    if (error == nil) {
        // stop current running advertisement
        if (self.peripheral.isAdvertising) {
            [self.peripheral stopAdvertising];
       // create advertisement dictionary containing service UUID and  name for the advertisement
        NSDictionary *advertisement = @{ CBAdvertisementDataServiceUUIDsKey : 
CBAdvertisementDataLocalNameKey: @"BLEServerApp" };

       // start advertisement
        [self.peripheral startAdvertising:advertisement];

You can now run the application. it will work like a peripheral. Make sure you turn on device bluetooth.

When the Peripheral Manager starts advertising the service, its delegate receives the message -peripheralManagerDidStartAdvertising:error: and when the Central subscribes to the service, the delegate receives -peripheralManager:central:didSubscribeToCharacteristic:. This is the place where you can generate dynamic data for the Central.

To send data to the Central, you need to prepare some chunk of data and then send updateValue:forCharacteristic:onSubscribedCentrals: to the Peripheral.

Conclusion : In this blog I have described how to create a basic BLE Peripheral Application making advertise using Core Bluetooth Framework. Lets see how to create application for BLE Central to listen these advertise in my next blog.... Happy Coding....