简体   繁体   English

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

[英]CLLocationManager requestAlwaysAuthorization popup shows and hides immediately

CLLocationManager requestAlwaysAuthorization popup shows and hides immediately, leaving user no time to press allow button. CLLocationManager requestAlwaysAuthorization弹出窗口立即显示和隐藏,使用户没有时间按允许按钮。 This is a class I wrote for location managing: 这是我为位置管理编写的一个类:

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
        }
    }

}

In my code I just write TMLocationManager.startLocationManager() 在我的代码中,我只写了TMLocationManager.startLocationManager()

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何清除错误-[CLLocationManager requestAlwaysAuthorization] - How to remove error -[CLLocationManager requestAlwaysAuthorization] 在requestAlwaysAuthorization之后立即使用CLLocationManager - Using CLLocationManager right after requestAlwaysAuthorization CLLocationManager没有定义requestAlwaysAuthorization或requestWhenInUseAuthorization - CLLocationManager does not define requestAlwaysAuthorization or requestWhenInUseAuthorization 何时必须调用 CLLocationManager requestAlwaysAuthorization? - When must CLLocationManager requestAlwaysAuthorization be called? 'CLLocationManager'的可见@interface没有声明选择器'requestAlwaysAuthorization' - No visible @interface for 'CLLocationManager' declares the selector 'requestAlwaysAuthorization' 如何在iOS 13中使用`requestAlwaysAuthorization`在CLLocationManager中请求地理位置? - How to request geolocation in CLLocationManager with `requestAlwaysAuthorization` in iOS 13? CLLocationManager requestAlwaysAuthorization第二次不显示警报 - CLLocationManager requestAlwaysAuthorization not showing alert second time 键盘显示然后在显示MFMessageComposeViewController时立即隐藏自己 - Keyboard shows then immediately hides itself when showing MFMessageComposeViewController CLLocationManager:以任何方式使用requestAlwaysAuthorization并仍然显示蓝色条吗? - CLLocationManager: any way to use requestAlwaysAuthorization and still have blue bar? CLLocationManager的按钮操作(当前位置弹出) - Button Actions for CLLocationManager(current location popup)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM