ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 'authorizationStatus()' was deprecated in iOS 14.0
    ios/개발하다가 2022. 4. 9. 21:48
    728x90

    접근 권한

     

    사용자의 위치 정보 서비스에 접근하려면 다음과 같이 작성하면 된다.

    switch CLLocationManager.authorizationStatus() {
    	case .notDetermined:
        	// blah blah
        case .restricted:
        	// blah blah
        case .authorizedAlways:
        	// blah blah
        case .authorizedWhenInUse:
        	// blah blah
        @unknown default:
        	break
        }

    하지만 'authorizationStatus()' was deprecated in iOS 14.0 라는  경고가 뜨는데 이 경고는 iOS 14부터 authorizationStatus를 사용하지 않아 수 없어 위 코드가 작동이 안된다는 것을 말한다.

     

    애플 공식문서에 가보면 

    https://developer.apple.com/documentation/corelocation/cllocationmanager/1423523-authorizationstatus

     

    locationManagerDidChangeAuthorization(_:)과 함께 authorizationStatus를 사용하라고 한다.

     

    func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
    
            switch manager.authorizationStatus {
                case .authorizedAlways , .authorizedWhenInUse:
                    break
                case .notDetermined , .denied , .restricted:
                    break
                default:
                    break
            }
            
            switch manager.accuracyAuthorization {
                case .fullAccuracy:
                    break
                case .reducedAccuracy:
                    break
                default:
                    break
            }
    }

     

    사실 이 방법 말고도 더 쉬운 방법이 있다.

     

    그냥 switch CLLocationManager.authorizationStatus() 를 switch CLLocationManager().authorizationStatus 로  바꿔서 작성하면된다.

     

    switch CLLocationManager().authorizationStatus {
    	case .notDetermined:
        	// blah blah
        case .restricted:
        	// blah blah
        case .authorizedAlways:
        	// blah blah
        case .authorizedWhenInUse:
        	// blah blah
        @unknown default:
        	break
        }

     

    728x90

    댓글

oguuk Tistory.