gpt4 book ai didi

ios - didEnterRegion、didExitRegion 未被调用

转载 作者:行者123 更新时间:2023-11-28 12:47:54 24 4
gpt4 key购买 nike

我一直在试验区域监控,以便在用户位于设定区域内时显示警报或本地通知。作为第一步,我添加了一个打印行以查看它是否适用于调试区域。但是,在打印其他行时,我没有得到 didEnterRegion 和 didExitRegion 的任何信息。

我正在模拟给定区域之内/之外的位置,但我没有运气。如果有人可以查看下面的代码并了解我错过了什么,那就太好了。谢谢。

    import UIKit
import CoreLocation

class ViewController: UIViewController, CLLocationManagerDelegate {

var manager = CLLocationManager?()



override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
manager = CLLocationManager()
let latitude: CLLocationDegrees = 48.858400
let longitude: CLLocationDegrees = 2.294500
let center: CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
let radius: CLLocationDistance = CLLocationDistance(100.0)
let identifier: String = "Notre Dame"

let currRegion = CLCircularRegion(center: center, radius: radius, identifier: identifier)

manager?.distanceFilter = 10
manager?.desiredAccuracy = kCLLocationAccuracyBest
currRegion.notifyOnEntry = true
currRegion.notifyOnExit = true

manager?.requestWhenInUseAuthorization()


manager?.delegate = self
manager?.pausesLocationUpdatesAutomatically = true

manager?.startMonitoringForRegion(currRegion)
manager?.startUpdatingLocation()


}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func locationManager(manager: CLLocationManager, didStartMonitoringForRegion region: CLRegion) {
print("The monitored regions are: \(manager.monitoredRegions)")
}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
print("locations = \(locValue.latitude) \(locValue.longitude)")
}

func locationManager(manager: CLLocationManager, didEnterRegion region: CLRegion) {
NSLog("Entered")
}

func locationManager(manager: CLLocationManager, didExitRegion region: CLRegion) {
NSLog("Exited")
}


}

最佳答案

你可以通过改变让它工作

manager?.requestWhenInUseAuthorization()

manager?.requestAlwaysAuthorization()

然后将此 key 添加到您的 info.plist 文件中NSLocationAlwaysUsageDescription 值为“This is for testing purpose”或您想要的任何文本,这将显示给请求使用位置的用户

关于ios - didEnterRegion、didExitRegion 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37498438/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com