I am doing a beacon ranging using Core Location with UUID, Major & Minor in my app. After ranging I need to connect that beacon using Core Bluetooth api. I am using estimote beacon in my application.
1 Answers
The ESTBeaconConnection class is what you're looking for. You can use the initWithBeacon initializer and pass it the CLBeacon object you got from ranging:
let bc = ESTBeaconConnection(beacon: myBeacon,
delegate: self,
startImmediately: true)
This'll initiate the connection process.
The delegate should implement the ESTBeaconConnectionDelegate protocol. When the connection is successfully established, you'll get a call to beaconConnectionDidSucceed, and you can start writing new settings to the beacon:
func beaconConnectionDidSucceed(connection: ESTBeaconConnection!) {
connection.writeMajor(123) { (newMajor, error) in
if (error != nil) {
println("successfully wrote the new major: \(newMajor)")
} else {
println("didn't write the new major, error was \(error)")
}
connection.disconnect()
}
}
It's also a good idea to implement the beaconConnectionDidFailWithError delegate—should something go south, you'll know about it.
Finally, since you can only connect to and change settings of your own beacons, you need to authenticate yourself before attempting to connect:
ESTCloudManager.setupAppID("appid", andAppToken: "app token")
You can generate the app token on https://cloud.estimote.com.