1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate{
let locationManager = CLLocationManager()
let region = CLBeaconRegion(proximityUUID: UUID(uuidString: "EBEFD083-70A2-47C8-9837-E7B5634DF567")!, identifier: "Discloth")
var detectedBeacon : CLBeacon?
// let colors = []
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startRangingBeacons(in: region)
// Do any additional setup after loading the view, typically from a nib.
}
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)
let disclothBeacons = beacons.filter{ $0.proximity != CLProximity.unknown }
if (disclothBeacons.count > 0) {
detectedBeacon = disclothBeacons[0] as CLBeacon
// self.view.backgroundColor = self.colors[detectedBeacon.minor.intValue]
}
}
} |
Partager