Это мой текущий подход, но моя ячейка tableview показывает только своего рода uuid. Что мне делать?
class iBeaconListVC: UIViewController, CLLocationManagerDelegate {
let lm = CLLocationManager()
var beaconsArray = [CLBeacon]()
let uuid1 = UUID(uuidString: "FDA50693-A4E2-4FB1-AFCF-C6EB07647825")
let uuid2 = UUID(uuidString: "AB8190D5-D11E-4941-ACC4-42F30510B408")
var beaconRegion1: CLBeaconRegion!
var beaconRegion2: CLBeaconRegion!
@IBOutlet weak var baconsListTV: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
lm.requestAlwaysAuthorization()
lm.delegate = self
let beaconRegion1 = CLBeaconRegion(proximityUUID: uuid1!, identifier: "beacon1")
let beaconRegion2 = CLBeaconRegion(proximityUUID: uuid2!, identifier: "beacon2")
lm.startRangingBeacons(in: beaconRegion1)
lm.startRangingBeacons(in: beaconRegion2)
}
func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
self.beaconsArray.removeAll()
if beacons.count > 0 {
beaconsArray.append(contentsOf: beacons)
for beacon in beacons {
print("info=\(beacon.proximityUUID.uuidString)major=\(beacon.major) minor=\(beacon.minor) accuracy=\(beacon.accuracy) rssi=\(beacon.rssi)")
self.baconsListTV.reloadData()
}
}
}
}
extension iBeaconListVC: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return beaconsArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let beacon = beaconsArray[indexPath.row]
let cell = self.baconsListTV.dequeueReusableCell(withIdentifier: "beaconsCell") as! BeaconsCell
cell.IDLabel.text = "UUID: " + String(beacon.proximityUUID.uuidString)
cell.detailLabel.text = "Details: Major = " + String(beacon.major.intValue) + " Minor = " + String(beacon.minor.intValue) + " Distance: " + String(beacon.proximity.rawValue)
cell.infoLabel.text = "RSSI: " + String(beacon.rssi)
return cell
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
}