Implement iBeacon Emitter in iOS Swift
Posted By : Varun Wadhwa | 10-Jan-2017

In this Blog I'll explain how to make an iPhone device act as a iBeacon emitter using swift.
iBeacons are devices allow Mobiles to listen signals and built upon technology of BLE (i.e Bluetooth Low Energy).
BLE operates on very low energy and use to transmit data in short distance . It transmit data in small packets (or Advertisement) at regular interval and has a one way communication support.
Beacons can broadcast at range of 110 meters
Format of BLE Advertising :
1. UUID : To uniquely identify large number of Beacon (related to each other).
2. Minor : To uniquely identify beacons.
3. Major : To differentiate sets of beacons from large number of beacons.
Steps to Implement Beacon broadcast :
Step 1. Import CoreBluetooth and CoreLocation framework.
import CoreBluetooth
import CoreLocation
Step 2. Conform to CBPeripheralManagerDelegate.
Step 3. Create instance of CLBeaconRegion and CBPeripheralManager class.
var beacon: CLBeaconRegion!
var data: NSDictionary!
var peripheralManager: CBPeripheralManager!
Step 4. To create and start broadcasting call the below code :
func startBeacon() {
let UUID = "6B5CDERF-285F-5TAC-A814-092E88G6C8F6"
let major: CLBeaconMajorValue = 567
let minor: CLBeaconMinorValue = 987
beacon = CLBeaconRegion(proximityUUID: NSUUID(uuidString: UUID)!, major: major, minor: minor, identifier: "IDENTIFIER")
data = beacon.peripheralDataWithMeasuredPower(nil)
peripheralManager = CBPeripheralManager(delegate: self, queue: nil, options: nil)
}
Step 5. To stop broadcast.
func stopBeacon() {
peripheralManager.stopAdvertising()
peripheralManager = nil
data = nil
beacon = nil
}
Step 6. Implement peripheralManagerDidUpdateState() func to handle change in Bluetooth services.
Thanks
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Varun Wadhwa
Varun is a mobile developer with experience in various technologies like Titanium , Cordova and native iOS development.