-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeaconTableViewController.swift
More file actions
executable file
·82 lines (57 loc) · 2.51 KB
/
BeaconTableViewController.swift
File metadata and controls
executable file
·82 lines (57 loc) · 2.51 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// BeaconTableViewController.swift
// CTZN
//
// Created by Dragos Victor Damian on 21/05/16.
// Copyright © 2016 Dragos Victor Damian. All rights reserved.
import Foundation
import UIKit
import CoreLocation
class BeaconTableViewController : UITableViewController{
@IBOutlet var beaconTableView: UITableView!
var beacons : Array<CLBeacon> = []
override func viewDidLoad() {
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(BeaconTableViewController.updateView(_:)), name: "updateBeaconTableView", object: nil)
//listen for notifications with selector updateView
}
func updateView(note: NSNotification!){
beacons = note.object! as! Array<CLBeacon>
beaconTableView.reloadData() //update table data
}
override func didReceiveMemoryWarning() {
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return beacons.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// debugPrint(beacons, separator: " , ", terminator: "")
let cell = tableView.dequeueReusableCellWithIdentifier("beaconCell", forIndexPath: indexPath) as UITableViewCell
let major = beacons[indexPath.row].major as NSNumber
let majorString = major.stringValue
let minor = beacons[indexPath.row].minor as NSNumber
let minorString = minor.stringValue
let proximity = beacons[indexPath.row].proximity
var proximityString = String()
let accuracy = String(format: "%.2f", beacons[indexPath.row].accuracy)
switch proximity
{
case .Near:
proximityString = "Near"
case .Immediate:
proximityString = "Immediate"
case .Far:
proximityString = "Far"
case .Unknown:
proximityString = "Unknown"
}
cell.textLabel?.text = "Major: \(majorString) Minor: \(minorString) Proximity: \(proximityString) Accuracy: \(accuracy)m"
//display beacon values in cell text label
return cell
}
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "Beacons in range"
}
}