gpt4 book ai didi

ios - CLLocationManager requestAlwaysAuthorization 弹出窗口立即显示和隐藏

转载 作者:行者123 更新时间:2023-11-30 13:31:29 25 4
gpt4 key购买 nike

CLLocationManager requestAlwaysAuthorization 弹出窗口立即显示和隐藏,让用户没有时间按下允许按钮。这是我为位置管理编写的类:

import UIKit

class TMLocationManager: NSObject, CLLocationManagerDelegate {
var locationManager: CLLocationManager?

override init() {
super.init()
}

static func startLocationManager() {
let manager = TMLocationManager()
manager.getPermission()
}

private func getPermission () {
locationManager = CLLocationManager()
locationManager!.desiredAccuracy = kCLLocationAccuracyBestForNavigation
locationManager!.delegate = TMLocationManager.init()

switch CLLocationManager.authorizationStatus() {
case .Denied, .Restricted:
return
case .NotDetermined:
locationManager!.requestAlwaysAuthorization()
break
case .AuthorizedAlways, .AuthorizedWhenInUse:
locationManager!.startUpdatingLocation()
default:
break
}
}

}

在我的代码中,我只是编写 TMLocationManager.startLocationManager()

最佳答案

结合我的评论,您需要确保 manager 变量被保留,因为一旦 startLocationManager 方法执行完毕后,它将被释放,并且警报将被解除。执行完毕。

关于ios - CLLocationManager requestAlwaysAuthorization 弹出窗口立即显示和隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36533418/

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