私はビーコンの近接性を示すアプリを作ろうとします。私はlabel
をこのデータを受け取るようにしましたが、私はできません。コンソールに表示されているすべてのデータではなく、近接性を表示したいだけです。 beacons[3]
で試してみますが、プログラムでエラーが出ます。Swift 2でラベルを貼るコンソール印刷
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet var metrosBeacon: UILabel!
let locationManager = CLLocationManager()
let region = CLBeaconRegion(proximityUUID: NSUUID(UUIDString: "FDA50693-A4E2-4FB1-AFCF-C6EB07647828")!, identifier: "MKT BEACONS")
// Note: make sure you replace the keys here with your own beacons' Minor Values
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
locationManager.delegate = self
if (CLLocationManager.authorizationStatus() != CLAuthorizationStatus.AuthorizedWhenInUse) {
locationManager.requestWhenInUseAuthorization()
}
locationManager.startRangingBeaconsInRegion(region)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion){
print (beacons)
metrosBeacon.text = "/(beacons)"
}}
コンソールデータ:
[CLBeacon(UUID:< __NSConcreteUUID 0x12ee586c0> FDA50693-A4E2-4FB1-AFCF-C6EB07647828、主要:10004、マイナー:54480、近接:1 +/- 0.05m、rssi:-32)]
ありがとうございました!
我々はbeacons
がCLBeaconオブジェクトの配列であることを
locationManager
の署名で見る
エラーがビーコン[3]よりも少ないので、起きていること4つのビーコンが見える。 @ eric-dのような解決策を使用して答えを示します。最初のものを取得するために 'beacons.first'にアクセスし、その近接フィールドにアクセスします。 – davidgyoung