2015-11-19 59 views
1

我使用Estimotes室內位置構建應用程序,任何我使用CoreLocation來查找我們的信標,並且我的應用程序將更改label.text。應用程序可以運行,但沒有工作,label.text不能更改。CoreLocation不能使用Estimotes Beacon

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" 
     } 
    } 
} 
+0

嘗試在didRangeBeacons中添加NSLog語句:inRegion:並在兩個if語句中。哪些日誌行被打印? – davidgyoung

+0

如果(knownBeacons.count> 0){NSLog(「find beacon」)和if(closestBeacon.minor.integerValue == 41016){NSLog(「catch」)}添加NSLog代碼,但輸出無法打印任何東西,我不知道爲什麼這個功能無法運行。 –

+0

在代碼中你初始化'locationManager'?我沒看到。可能是零嗎? – davidgyoung

回答

0

首先要嘗試:

我會移動的locationManger = CLLocationManager()初始化類的實例聲明內外viewDidLoad。在對象構建期間,我發現初始化位置管理器時遇到了問題。

+0

謝謝,我發現我的問題。我在測試App時忘記了允許corelocaiotn,所以我無法使用 –