iBeacon app - receiving/transmitting at the same t

2020-07-23 09:51发布

问题:

How can my app transmit its iBeacon (to advertise itself) AND range for other iBeacons (to discover peers running the same app) at the same time?

Are there any code samples out there?

回答1:

Yes, this is possible. You can see for yourself by downloading my Locate for iBeacon app and trying it on two iOS devices simultaneously. You can turn on a transmitter on each device and simultaneously range for iBeacons and successfully see the iBeacon transmission from the other device.

The only limitations are that this only works in the foreground, and an iOS device will not see it's own transmission when ranging.

There is not really any trick to doing this. Any sample code for transmitting or ranging works fine... Just set them both up at the same time.



回答2:

Agree with David. I have built an app doing this but the problem is the foreground requirement (for transmitting) which makes it harder to do iPhone to iPhone beaconing. A good workaround is using the Core Bluetooth framework as opposed to the iBeacons.

Useful links:

http://mobile.tutsplus.com/tutorials/iphone/ios-7-sdk-core-bluetooth-practical-lesson/

iBeacon in the background - Use cases



回答3:

You can broadcast (peripheral mode) in the background on iOS now. It was broken for a little while when iOS 10 came out, but seems like it was fixed with iOS 10.0.2 according to this thread: https://forums.developer.apple.com/thread/51309

So it seems you can broadcast + receive with your app in either the foreground or background now.