Leke Abolade
Leke Abolade

Reputation: 1

displaying data from beacons

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

Answers (2)

Ashvini
Ashvini

Reputation: 352

  1. First check your configured proximityUUID which is used to create CLBeaconRegion is correct.
  2. Your specified beacon should be active that means it should not be discharged and it should be ON so that it can be visible to your device when your device will be entered in specified beacon's region.
  3. Also check your Info.plist and make sure that it should contain pair as NSLocationWhenInUseUsageDescription. So that your app will prompt you for your location access and you should Allow access to it.
  4. Your bluetooth should be ON.

Upvotes: 0

davidgyoung
davidgyoung

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

Related Questions