使用多个iBeacon

时间:2015-11-03 14:44:24

标签: swift cllocation beacon

我关于信标的项目,当它最接近信标时显示图像,当它转到另一个信标时,它会显示另一个图像。我试图通过使用if语句来解决这个问题,我不知道该怎么做它给我看错误。

func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
    if BEACON_1_UUID = BEACON_1_MAJOR {

        var closestBeacon = beacons[0]

      //  print("major = \(closestBeacon.major) minor = \(closestBeacon.minor)")

        if closestBeacon != lastFoundBeacon || lastProximity != closestBeacon.proximity {
                lastFoundBeacon = closestBeacon
                lastProximity = closestBeacon.proximity

                var  proximityMessage: String!

                switch lastFoundBeacon.proximity {

                case CLProximity.Immediate:

                    if BEACON_1_MAJOR = closestBeacon {
                        proximityMessage = "Very Close"
                        txtDesc.text = "hi"
                        imageview.image = UIImage(named: "CC_Zoe-Francois_No-Bake-Strawberry-Cheesecake.jpg");
                        self.checkIn("Leaving", comment: "Checking In")
                        self.view.backgroundColor = UIColor.redColor()
                        txtre.text! += "Very Close to \(closestBeacon.major) \(closestBeacon.minor) \n"
                    } else { /* ... */ }

                case CLProximity.Near:
                    proximityMessage = "Near"
                    // manager.stopRangingBeaconsInRegion(bRegion)
                    self.view.backgroundColor = UIColor.orangeColor()
                   txtre.text! += "Near \(closestBeacon.major) \(closestBeacon.minor) \n"

                case CLProximity.Far:
                    proximityMessage = "Far"

                    txtre.text! += "Far from \(closestBeacon.major) \(closestBeacon.minor) \n"

                    self.view.backgroundColor = UIColor.greenColor()

                    //self.checkIn("out")
                    self.sendNotification("Good Bye")

                default:
                    proximityMessage = "Where's the Beacon?"
                }
        }
    }
}

0 个答案:

没有答案