iosswiftcore-locationcore-bluetoothbeacon

Using CoreLocation and CoreBluetooth scan beacons at the same time


Im responsible of development of an app in which I need to scan for beacons, and so far support for iBeacon beacons only was enough and in order to do that I used CoreLocation to scan and retrieve data of the beacons which worked very good.

Now it is required to add support for scanning Eddystone beacons; but CoreLocation does not support this type of beacons. Hence, I must use CoreBluetooth to scan and retrieve data from Eddystone beacons, please refer to this very informative post from @davidgyoung for further understanding.



https://stackoverflow.com/a/41744019/6792878



So, since CoreLocation and CoreBluetooth are using bluetooth, I started to think of best practice to follow for scanning both beacons types as good as possible, I came up with the following:


Solution

  • If you want to scan both iBeacon and other beacon types on iOS, you must use both CoreLocation and CoreBluetooth. They work fine together.

    It is important to note that it is not possible to scan iBeacon with CoreBluetooth as iOS blocks access to the raw bytes of any packet matching the iBeacon format by returning an empty manufacturer data NSData object.

    To see an example of these working together with no trouble, check out my Beacon Scope app for iOS which scans both iBeacon (with CoreLocation) and Eddystone and AltBeacon with CoreBluetooth. Turn on both beacon types in the vicinity and the app detects both at the same time. Indeed, the sample screen shots on the AppStore show this.

    While the code for that app is not open source, the basics of how it scans for AltBeacon and CoreBluetooth are open source in the iOS Beacon Tools project.