Reputation: 1
I am working on a native app to use apple's iBeacon framework and trying to log to the console a list of all the bluetoooth devices in my proximity. I have been following this tutorial but when I run the app nothing is printed to the console. Where is my error?
Below is the full detail of the view controller file I have written:
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
let locationManager = CLLocationManager()
let region = CLBeaconRegion(proximityUUID: NSUUID(uuidString: "852c0828-fe67-4dd7-b8ff-52852a66851e")! as UUID, major: 8008, minor: 1337, identifier: "Testing")
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
locationManager.delegate = self
if (CLLocationManager.authorizationStatus() != CLAuthorizationStatus.authorizedWhenInUse) {
locationManager.requestWhenInUseAuthorization()
}
locationManager.startRangingBeacons(in: region)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
print(beacons)
print("hello")
}
}
Nothing is printed to the console on runtime, including the "hello".
Upvotes: 0
Views: 163
Reputation: 352
Upvotes: 0
Reputation: 64916
The code looks good. Are you sure you know your beacon identifier and that it is transmitting?
I would try to use an off the shelf beacon detector app like Locate to verify it can see your beacon. Note you must configure your beacon UUID in the app for detection.
A few other tips:
Make sure your Info.plist contains an entry like this otherwise it won't be able to prompt you for location access: <key>NSLocationWhenInUseUsageDescription</key><string>This app needs to access your location so it can tell when you are near a beacon.</string>
Make sure you are prompted for location access and you have actually granted it. Check in Settings -> [Your app name] -> Location, and verify it says "ALLOW LOCATION ACCESS" has a checkmark that is not next to Never.
Make sure bluetooth is on.
Upvotes: 1