多次执行的操作 iBeacon
Actions executed multiple time iBeacon
我正在玩 iBeacons,我想在特定信标在范围内时只执行一次功能或命令。这是我的代码:https://gist.github.com/Silvering/f3dc4edf32eb55afe433
当信标在范围内时,我收到 "Its the purple" x10000
我只想显示此消息一次。有什么想法吗?
为此,您基本上可以做两件事
- 找到你的信标后删除位置委托,这样你就不会再接到任何电话
- 请记住,您已经找到了该信标(例如,在某个数组中)并使用将跳过它的条件扩展您的逻辑,以防它应该多次出现。
所以像这样:
// Create storage for located beacons
var locatedBeacons = [Int]()
// Adds beacon to storage
func beaconLocated(beaconId : Int) {
self.locatedBeacons.append(beaconId)
}
// Already located?
func isBeaconLocated(beaconId : Int) -> Bool {
return contains(self.locatedBeacons, beaconId)
}
我正在玩 iBeacons,我想在特定信标在范围内时只执行一次功能或命令。这是我的代码:https://gist.github.com/Silvering/f3dc4edf32eb55afe433 当信标在范围内时,我收到 "Its the purple" x10000 我只想显示此消息一次。有什么想法吗?
为此,您基本上可以做两件事
- 找到你的信标后删除位置委托,这样你就不会再接到任何电话
- 请记住,您已经找到了该信标(例如,在某个数组中)并使用将跳过它的条件扩展您的逻辑,以防它应该多次出现。
所以像这样:
// Create storage for located beacons
var locatedBeacons = [Int]()
// Adds beacon to storage
func beaconLocated(beaconId : Int) {
self.locatedBeacons.append(beaconId)
}
// Already located?
func isBeaconLocated(beaconId : Int) -> Bool {
return contains(self.locatedBeacons, beaconId)
}