didEnterRegion和didExitRegion在iOS8中不起作用

丽贝卡·马丁(Rebecca Martin)

我正在使用“核心位置”来跟踪区域,以便检测用户是否输入o退出该区域。

不幸的是,我的代码只能在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()

任何的想法?谢谢。

FDF

通过在我的.plist文件中设置“ NSLocationAlwaysUsageDescription ”,我可以使它正常工作

我不确定是否在应用未运行时是否会增加电池使用量,但是这会在进入和退出时通知我...

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

NSUserDefaults standardUserDefaults在iOS8中不起作用

设置keyWindow rootViewController在iOS8中不起作用

UIMoviePlayerControllerDidEnterFullscreenNotification在iOS8中不起作用

定位服务在iOS8中不起作用

Phonegap / Cordova在iOS8中不起作用

iOS 7缩放在带有AutoLayout的ScrollView中不起作用,但在iOS8 / 9中起作用

在iOS8中使用UIActionSheet显示UIPickerView不起作用

在iOS8中使用ModalPresentationStyle OverCurrentContext时ScrollsToTop不起作用

UIActivityViewController在iOS 8中不起作用

MPVolumeView在iOS 8中不起作用

CCClippingNode在iOS 8中不起作用

scrollToRowAtIndexPath在iOS 8中不起作用

支持多接口,但主屏幕中只有一个接口在iOS8 + iPhone中不起作用

升级到iOS8后,UITableView didSelectRowAtIndexPath不起作用

滚动后,IOS8 Safari网站链接不起作用

在pushState之后的iOS8 Safari:nth-child()选择器不起作用

Adobe Air for iOS8:地理位置不起作用

IOS8寄存器通知不起作用。为什么?

Bootstrap Tokenfield在移动Safari / iOS 8中不起作用

定位服务在iOS 8中不起作用

选择菜单在iOS 8中不起作用

核心位置在iOS 8中不起作用

自定义字体在iOS 8中不起作用

成为FirstResponder在iOS 8中不起作用

Javascript代码在ios和Safari中不起作用

TapGestureRecognizer 在 iOS 和 UWP 中不起作用

iOS8动画代码不再起作用

使用第三方IME时,JS keydown keyup keypress事件在IOS8上不起作用

SDWebImage在iOS 8上不起作用