/
BREBeacon.swift
52 lines (39 loc) · 1.21 KB
/
BREBeacon.swift
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
//
// BREBeacon.swift
// BeaconRangingExample
//
// Created by Sam Piggott on 05/04/2017.
// Copyright © 2017 Sam Piggott. All rights reserved.
//
import UIKit
import CoreLocation
enum BREBeaconStrength:Int {
case whisper = -89
case mutter = -85
case talk = -82
case shout = -75
case scream = -63
}
class BREBeacon: NSObject {
var title:String
var major:Int
var minor:Int
var strength:BREBeaconStrength
var shouldTrigger:Bool
init?(dictionary:[String:Any]) {
guard
let title = dictionary["beacon_name"] as? String,
let major = dictionary["major"] as? Int,
let minor = dictionary["minor"] as? Int,
let strengthInt = dictionary["strength"] as? Int,
let strength = BREBeaconStrength(rawValue: strengthInt),
let shouldTrigger = dictionary["should_trigger"] as? Bool
else { return nil }
self.title = title
self.major = major
self.minor = minor
self.strength = strength
self.shouldTrigger = shouldTrigger
}
func isInRange(rssi:Int) -> Bool { return rssi > strength.rawValue }
}