【发布时间】:2017-03-12 15:24:03
【问题描述】:
我正在做一个项目,但一个区域的监控功能不起作用。
所以我创建了一个非常简单的项目来测试这个功能。 我发现了一个有趣的情况。
代码如下:
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var map: MKMapView!
let clMan = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
map.showsUserLocation = true
clMan.requestWhenInUseAuthorization()
clMan.delegate = self
clMan.startUpdatingLocation()
clMan.startMonitoring(for:CLCircularRegion(center: CLLocationCoordinate2D.init(latitude: 51.5100888, longitude: -0.134575500000008), radius: 1000, identifier: "Picca")
)
}
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
print(region)
}
}
奇怪的是,如果我改变了
requestWhenInUseAuthorization() 与
requestAlwaysAuthorization() 我的代码有效!
我将 Piccadilly Circus 设置为使用该位置的模拟进行测试。 在去伦敦之前,我设置了另一个城市,然后是伦敦!
【问题讨论】:
标签: ios swift mapkit core-location