I am having an issue reconnecting to a beacon. I come in through a view controller via a button and segue to another view controller and connect to a beacon. No problem. I then cancel the connection and leave the view controller going back to the first view controller. i push the button to again connect to the same beacon but it won’t connect. I am using SDK 3.5.0. Any suggestions?
Looks like a bug in the SDK. We’ll get to fixing that; in the meantime, deallocating the old ESTBeaconConnection object and allocating a new one should do the trick.
Where is that method located in the SDK?
Trying to be more specific…How do i deallocate the old ESTBeaconConnection in Swift. I have tried a number of things and nothing seems to work.
Either set it to nil, or simply replace it with a new instance of ESTBeaconConnection:
var beaconConnection: ESTBeaconConnection? // first connection: self.beaconConnection = ESTBeaconConnection(...) self.beaconConnection.startConnection() // ... doing something ... self.beaconConnection.disconnect() // 2nd connection // create a new instance of ESTBeaconConnection // the old one will be automatically dealloc'ed by ARC self.beaconConnection = ESTBeaconConnection(...) // ...
I tried both of these. The "nil"option gives me a compiler error “Cannot assign a value of type ‘nil’ to a value of type ‘ESTBeaconConnection’”. the line of code is:
self.beaconConnection! = nil
And the second option doesn’t doesn’t come back from the ‘startConnection’ with a ‘beaconConnectionDidSucceed’ when trying to establish a second connection. the first connections works great.
To be able to assign a “nil” value to a property, you need to declare it as:
var beaconConnection: ESTBeaconConnection?
i.e., both mutable, and optional. I think
var beaconConnection: ESTBeaconConnection!
should also work.
Do you also have the
I tried both of those syntax’s and get the same compiler error.
I did implement beaconConnection:didFailWithError. I have an alert pop up when an error occurs on the connection. I tested it by making sure the beacon was out of range when i initiated the connection. The alert popped up as expected.
With the beacon in range and attempting the second connection,I do not get any alert.