I am trying to make a simple treasure hunt app that makes use of estimote beacons (I have 3 beacons). So I currently have a home screen with a button to start the hunt; when the button is pressed, the next view controller is the first clue. When the device is within 'near' proximity to first beacon, the screen changes to indicate that the user is getting closer. When the device is in the immediate proximity, a question appears with a text field and 'save question' button. (All of this is done in one view controller, using code to determine what items are shown and when). The user answers the question, then when they click 'save question', their answer is saved to a table view, and clue 2 appears. (I've not done any of the saving yet)
My aim is to loop through again. So instead of creating a new view controller for each 'round' of clue-->getting close-->question, I want to loop back to the same view controller as before - I want to be able to add more questions/clues in the future if I get more beacons, so I'm trying to find the most efficient way of doing it (I hope that makes sense!). I feel like I need a for loop somewhere, but I can't figure out where.
let questionTitleArray: [String] = ["Question One", "Quesiton Two", "Question Three"]
let clueTitleArray: [String] = ["Clue One", "Clue Two", "Clue Three"]
let questions = [
11711: "Emporer and King are types of which flightless bird?",
41848: "What illuminated word appears on the roof of a London cab?",
24952: "Name the fictional boxer played by Sylvester Stallone"]
let clues: [String] = ["I'm your first clue", "I'm your second clue", "I'm your third clue"]
let questionsArray: [String] = ["Emporer and King are types of which flightless bird?", "What illuminated word appears on the roof of a London cab?", "Name the fictional boxer played by Sylvester Stallone"]
var temperatureImage: [String] = ["fireplace-hi.png"]
let temperatureArray: [String] = ["Getting warmer...", "Getting colder...", "Freezing!"]
let minorValuesArray:[Int] = [11711, 41848, 24952]
//var i = 0
override func viewDidLoad() {
super.viewDidLoad()
self.image.alpha = 0
self.textBox.alpha = 0
self.button.alpha = 0
var i = 0
questionLabel.text = clueTitleArray[i]
question.text = clues[i]
locationManager.delegate = self
if (CLLocationManager.authorizationStatus() != CLAuthorizationStatus.AuthorizedWhenInUse)
{
locationManager.requestWhenInUseAuthorization()
}
locationManager.startRangingBeaconsInRegion(region)
}
func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
print(beacons)
let knownBeacons = beacons.filter
{
$0.proximity != CLProximity.Unknown
}
if (knownBeacons.count > 0)
{
let closestBeacon = knownBeacons[0] as CLBeacon
//insert a for loop
var i = 0
//for var i = 0; i < minorValuesArray.count; i++
//while i < minorValuesArray.count
if closestBeacon.minor.integerValue == minorValuesArray[i] && closestBeacon.proximity == CLProximity.Near //if the beacon is purple (clue1) and proximity is near, hide the labels and just show image
{
self.questionLabel.text = temperatureArray[0]
self.button.alpha = 0
self.textBox.alpha = 0
self.image.alpha = 1
self.question.alpha = 0
}
else if closestBeacon.minor.integerValue == minorValuesArray[0] && closestBeacon.proximity == CLProximity.Immediate //if the beacon is purple and proximity is immediate (user is in the right place), show aa success message and the next question. Stop ranging so the screen doesn't flicker back to warm.
{
self.image.alpha = 0
self.questionLabel.alpha = 1
self.question.alpha = 1
self.questionLabel.text = self.questionTitleArray[i]
self.question.text = self.questionsArray[i]
self.textBox.alpha = 1
self.button.alpha = 1
locationManager.stopRangingBeaconsInRegion(region)
}
}
}