【问题标题】:CoreLocation can't use with Estimotes BeaconCoreLocation 不能与 Estimotes Beacon 一起使用
【发布时间】:2015-11-19 14:40:43
【问题描述】:

我使用 Estimotes 室内位置构建了一个应用程序,任何我使用 CoreLocation 来查找我们的信标,我的应用程序都会更改 label.text。应用程序可以运行,但没有工作,label.text 不能改变。

   override func viewDidLoad() {
   super.viewDidLoad()

    let path = NSBundle.mainBundle().pathForResource("location", ofType: "json")
    do {
    let content = try String(contentsOfFile: path!, encoding: NSUTF8StringEncoding)

    let locationSetup = ESTLocationBuilder.parseFromJSON(content)

    //set up delegate
    manager.delegate = self
    locationManager.delegate = self  
 if (CLLocationManager.authorizationStatus() !=  CLAuthorizationStatus.AuthorizedWhenInUse) {
        locationManager.requestWhenInUseAuthorization()
    }
    locationManager.startRangingBeaconsInRegion(region)
}
  func locationManager(manager: CLLocationManager, didRangeBeacons beacons:[CLBeacon], inRegion region: CLBeaconRegion){

    let knownBeacons = beacons.filter{ $0.proximity != CLProximity.Unknown }
    if (knownBeacons.count > 0){
        let closestBeacon = knownBeacons[0] as CLBeacon
        if(closestBeacon.minor.integerValue == 41016)
        {
            self.snow.text = "find"
        }
    }
} 

【问题讨论】:

  • 尝试在 didRangeBeacons:inRegion: 和两个 if 语句中添加 NSLog 语句。打印哪些日志行?
  • 我在代码中添加 NSLog,如果 (knownBeacons.count > 0){ NSLog("find beacon") 和 if(closestBeacon.minor.integerValue == 41016){ NSLog("catch") }但是Output不能打印任何东西,不知道为什么这个函数不能运行。
  • 你在代码的什么地方初始化locationManager?我没看到。它可能为零吗?
  • let locationManger = CLLocationManager(),我已经在课堂上声明了

标签: swift2 core-location ibeacon estimote


【解决方案1】:

首先要尝试:

我会将locationManger = CLLocationManager() 的初始化移到类实例声明之外和viewDidLoad 内。我在对象构造过程中看到了初始化位置管理器的问题。

【讨论】:

  • 谢谢,我找到了我的问题。我在测试 App 时忘记允许 corelocaiotn,所以我不能使用
猜你喜欢
  • 1970-01-01
  • 2015-05-20
  • 1970-01-01
  • 2012-09-25
  • 2017-01-09
  • 2017-04-14
  • 2016-09-16
  • 2016-04-19
  • 1970-01-01
相关资源
最近更新 更多