With iOS 7 you could easily range and scan for beacons in your application with just a few lines of code. `CLLocationManger` took care of all of the heavy lifting for you and things were just enabled for you automatically. With iOS 7.1 your users got prompted that you were going to do some scanning and it required Bluetooth. This was alright since the system took care of it for you automatically.
Enter iOS 8
While iOS 8 hasn’t added too many new feature for iBeacons that I can tell thus far, they did change the API for developer to enable iBeacon support in there application.When you create a new instance of CLLocationmanager
it is extremely important that you call the following:
manager = new CLLocationManager();
manager.RequestWhenInUseAuthorization ();
//This is used if you are doing anything in the foreground.manager.RequestAlwaysAuthorization ();
// This is used if you want to scan in the background
Of course these are iOS 8 only methods so makes sure to do a version check with: UIDevice.CurrentDevice.CheckSystemVersion (8, 0);
But wait there is more!
This isn’t enough though to prompt your user for access to iBeacons. You will need to now modify your Info.plist! You will need to add a new string entry called NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription. Then you can specify the message you want to prompt your user with when attempting to scan for iBeacons.Now we can return to happy iBeacon Scanning!