How to change connect to beacon and minor value using SDK

I am trying to change Minor Value using Estimate SDK. But having problem connecting to Beacon let alone changing the value. Here is my implementation

let beaconConnection = ESTBeaconConnection()

//Start raining Beacon

        proximityUUID: NSUUID(UUIDString: "B9407F30-F5F8-466E-AFF9-25556B57FE6D"),
        major: 57048, identifier: "monitored region"))

//Connect to in range beacon

func beaconManager(manager: AnyObject!, didRangeBeacons beacons: [AnyObject]!, inRegion region: CLBeaconRegion!) {

// Change minor value when ConnectionDidSucceed

func beaconConnectionDidSucceed(connection: ESTBeaconConnection!) {
    let minor = 22905
    let newMinor = 2222
    beaconConnection.writeMinor(UInt16(minor), completion: {(newMinor: UInt16, errorMajor: NSError!) -> Void in})

I’ve also implemented didFailWithError to catch any error

func beaconConnection(connection: ESTBeaconConnection!, didFailWithError error: NSError!) {
    println("not successful")

Although didRangeBeacons finds the correct Beacon, but I,m unable to connect to it and it appears that beaconConnection.startConnection() does nothing.

Any help would be much appreciate.

Change your beaconConnection property to:

let beaconConnection = ESTBeaconConnection(
    proximityUUID: NSUUID(UUIDString: "B9407F30-F5F8-466E-AFF9-25556B57FE6D"),
    major: 57048, minor: 22905, delegate: self)

… and your beaconConnectionDidSucceed method to:

func beaconConnectionDidSucceed(connection: ESTBeaconConnection!) {
    connection.writeMinor(2222, completion: { (newMinor, error) -> Void in
        if error != nil {
            println("error: \(error)")
        } else {
            println("successfully changed minor, new value: \(newMinor)")

This should help.

Explanation: you need to tell the ESTBeaconConnection object which beacon to connect to. In the first code snippet above, we do that explicitly but specifying the UUID, major and minor values. This means that you don’t even need to range for the beacon—although it doesn’t hurt to do that, to make sure that it’s in range before attempting to connect.

1 Like

Hey thanks alot, it worked!

quick question, is this a normal behaviour of beacon to stop advertising when in connected state.

Yes, that’s how it currently works.