我正在使用Core Location來跟蹤區域,以檢測用戶是否輸入o退出此區域。didEnterRegion和didExitRegion在iOS8中不起作用
不幸的是,我的代碼適用於iOS7,但不適用於iOS8。
這是我使用的代碼:
func setMonitoredRegion() {
var startLocation: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: +52.53753000, longitude: +13.35971000)
var monitoredRegion = CLCircularRegion(center: startLocation, radius: 100, identifier: "Region Test")
locationManager.startMonitoringForRegion(monitoredRegion)
}
該地區開始在委託方法didStartMonitoringForRegion被跟蹤:
func locationManager(manager: CLLocationManager!, didStartMonitoringForRegion region: CLRegion!) {
println("Starting monitoring \(region.identifier)")
}
但在iOS8上的方法didEnterRegion和didExitRegion不所謂:
func locationManager(manager: CLLocationManager!, didEnterRegion region: CLRegion!) {
println("Entered Region \(region.identifier)")
self.showAlertViewWithTitle("Enter Region", message: "The user has entered in monitored region").show()
}
func locationManager(manager: CLLocationManager!, didExitRegion region: CLRegion!) {
println("Exited Region \(region.identifier)")
self.showAlertViewWithTitle("Exit Region", message: "The user has left monitored region").show()
}
此外,我沒有收到任何錯誤:
func locationManager(manager: CLLocationManager!, monitoringDidFailForRegion region: CLRegion!, withError error: NSError!) {
println("Error:" + error.localizedDescription)
}
或者:
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
println("Error:" + error.localizedDescription)
}
在iOS8上我已經包括以下鑰匙插入Info.plist文件:
NSLocationWhenInUseUsageDescription
並在代碼中,我獲得用戶授權:
locationManager.requestWhenInUseAuthorization()
有什麼想法?謝謝。
那些入口和出口方法將觸發與NSLocationWhenInUseUsageDescription或不? – Ramakrishna 2017-02-07 09:54:27