iOS 14弃用了CLLocationManager的AuthorizationStatus [英] AuthorizationStatus for CLLocationManager is deprecated on iOS 14

查看:878
本文介绍了iOS 14弃用了CLLocationManager的AuthorizationStatus的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码检查我是否有权访问用户位置

I use this code to check if I have access to the user location or not

   if CLLocationManager.locationServicesEnabled() {
        switch CLLocationManager.authorizationStatus() {
        case .restricted, .denied:
            hasPermission = false
        default:
            hasPermission = true
        }
    } else {
        print("Location services are not enabled")
    }

Xcode(12)向我大喊:

And Xcode(12) yells at me with this warning:

'authorizationStatus()' was deprecated in iOS 14.0

那是什么替代品?

推荐答案

它现在是CLLocationManager authorizationStatus .因此,创建一个CLLocationManager实例:

let manager = CLLocationManager()

然后您可以从那里访问该属性:

Then you can access the property from there:

switch manager.authorizationStatus {
case .restricted, .denied:
    hasPermission = false
default:
    hasPermission = true
}

iOS 14中有一些与位置相关的更改.请参阅WWDC 2020 新功能在位置.

There are a few location related changes in iOS 14. See WWDC 2020 What's new in location.

这篇关于iOS 14弃用了CLLocationManager的AuthorizationStatus的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆