0
votes

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
How can u start ranging before connecting to beacon ? - iAnurag
I agree with @iAnurag .For ranging you have to create region objects and start monitoring. once you start monitoring then only delegate methods are called. What functionality are you trying to implement ?? - ak_tyagi
I am creating CLBeacon Region for ranging. After ranging I need to connect that beacon using Core Bluetooth for modifying their characteristics. (Thanks @iAnurag, @iAKST). - Gautam Sareriya
R u trying to modify UUID, major and minor? - iAnurag
I am trying to Modify their UUID, Major, Minor and tx power Of beacon. @iAnurag - Gautam Sareriya

1 Answers

0
votes

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.