Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 迪登特地区和迪登特地区;我不能在iOS8中工作_Swift_Ios8_Location - Fatal编程技术网

Swift 迪登特地区和迪登特地区;我不能在iOS8中工作

Swift 迪登特地区和迪登特地区;我不能在iOS8中工作,swift,ios8,location,Swift,Ios8,Location,我使用核心位置来跟踪一个区域,以便检测用户是否进入或退出该区域 不幸的是,我的代码可以在iOS7中工作,但不能在iOS8中工作 这是我正在使用的代码: func setMonitoredRegion() { var startLocation: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: +52.53753000, longitude: +13.35971000) var monitoredRegio

我使用核心位置来跟踪一个区域,以便检测用户是否进入或退出该区域

不幸的是,我的代码可以在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)
}
或:

在iOS8中,我已将以下密钥包括在info.plist文件中:

NSLocationWhenInUseUsageDescription
在代码中,我获得用户授权:

locationManager.requestWhenInUseAuthorization()

有什么想法吗?谢谢。

别忘了激活通知属性:

self.beaconRegion.notifyOnEntry=YES;
self.beaconRegion.notifyOnExit=YES;
self.beaconRegion.notifyEntryStateOnDisplay=YES;

通过在.plist文件中设置“NSLocationAlwaysUsageDescription”,我可以实现这一点


我不确定这是否会在应用程序未运行时提高电池使用率,但这允许我在进入和退出时收到通知…

在locationManager之前,我已将其用于我的CLCircularRegion区域。使用它启动MonitoringForRegion(monitoredRegion)不起作用:(无论是否使用UsageDescription,这些进入和退出方法都将使用NSLocation触发??
self.beaconRegion.notifyOnEntry=YES;
self.beaconRegion.notifyOnExit=YES;
self.beaconRegion.notifyEntryStateOnDisplay=YES;