Reputation: 1
Is it possible to detect iBeacons without knowing their UUID? Is there any way to use Core Bluetooth or some other method?
Upvotes: 0
Views: 536
Reputation: 64941
While you cannot detect beacons on iOS without specifying the ProximityUUID up front, you can set up ranging to look for a large number of ProximityUUIDs -- I have successfully ranged for 100 of them at the same time (although 1000 crashes my app.)
By using an online beacon database, you can find a list of UUIDs known to be close to you. This won't detect every beacon for sure, but it will allow you to detect many that are around you without having to build the UUIDs into your app.
Here's an example using the NingoSDK to get the 100 nearest ProximityUUIDs to your location and register them for ranging.
let locationManager = CLLocationManager()
// Get up to 100 beacon ProximityUUIDs within 1km from our current location, so we can use these for beacon ranging
let queryClient = QueryBeaconClient(authToken: Settings().getSetting(key: Settings.ningoReadonlyApiTokenKey)!)
queryClient.queryFirstIdentifiers(latitude: latitude, longitude: longitude, radiusMeters: 1000, limit: 100) { (proximityUUIDStrings, errorCode, errorDetail) in
if let proximityUUIDStrings = proximityUUIDStrings {
NSLog("There are now \(proximityUUIDStrings.count) nearby beacon uuids")
if proximityUUIDStrings.count > 0 {
for region in locationManager.rangedRegions {
locationManager.stopRangingBeacons(in: region as! CLBeaconRegion)
}
for uuidString in proximityUUIDStrings {
let region = CLBeaconRegion(proximityUUID: UUID(uuidString: uuidString)!, identifier: uuidString)
locationManager.startRangingBeacons(in: region)
}
BeaconTracker.shared.updateTransientUuids(uuids: proximityUUIDStrings)
}
}
}
Upvotes: 0
Reputation: 114866
You must know at least the UUID you are looking for in order to create a CLBeaconRegion
. There is no way on iOS to scan for "all beacons".
iBeacons are specifically obscured from Core Bluetooth discovery.
Upvotes: 2