- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在做一个项目,但是某个区域的监控功能不起作用。
所以我创建了一个非常简单的项目来测试这个功能。我发现了一个有趣的情况。
代码如下:
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 设置为使用模拟位置进行测试。去伦敦之前定了另一个城市,后来又定了伦敦!
最佳答案
来自documentation :
If the user grants “when-in-use” authorization to your app, your app can start most (but not all) location services while it is in the foreground. (Apps cannot use any services that automatically relaunch the app, such as region monitoring or the significant location change service.
更多来自 documentation :
In iOS, registered regions persist between launches of your app. If a region boundary crossing occurs while your iOS app is not running, the system automatically wakes it up (or relaunches it) in the background so that it can process the event.
关于ios - startMonitoring 不适用于 "WhenInUseAuthorization"权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42749194/
我是一名优秀的程序员,十分优秀!