사용자의 위치 승락 여부 확인 [iOS]
위치 기반 앱을 개발하면 당연히 사용자의 위치를 얻어오는 요청을 한번 이상 하고 이걸 거절할 경우에 따른 예외처리도 매우 중요하다. 사용자의 위치값에 대한 승인여부는 다음과 같은 메소드를 호출하면 확인할 수 있다.
1 |
[CLLocationManager authorizationStatus]; |
리턴값은 CLAuthorizationStatus 형식으로 오며 헤더파일을 보면 다음과 같이 온다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
typedef NS_ENUM(int, CLAuthorizationStatus) { // User has not yet made a choice with regards to this application kCLAuthorizationStatusNotDetermined = 0, // This application is not authorized to use location services. Due // to active restrictions on location services, the user cannot change // this status, and may not have personally denied authorization kCLAuthorizationStatusRestricted, // User has explicitly denied authorization for this application, or // location services are disabled in Settings. kCLAuthorizationStatusDenied, // User has granted authorization to use their location at any time, // including monitoring for regions, visits, or significant location changes. kCLAuthorizationStatusAuthorizedAlways NS_ENUM_AVAILABLE(NA, 8_0), // User has granted authorization to use their location only when your app // is visible to them (it will be made visible to them if you continue to // receive location updates while in the background). Authorization to use // launch APIs has not been granted. kCLAuthorizationStatusAuthorizedWhenInUse NS_ENUM_AVAILABLE(NA, 8_0), // This value is deprecated, but was equivalent to the new -Always value. kCLAuthorizationStatusAuthorized NS_ENUM_DEPRECATED(10_6, NA, 2_0, 8_0, "Use kCLAuthorizationStatusAuthorizedAlways") __TVOS_PROHIBITED __WATCHOS_PROHIBITED = kCLAuthorizationStatusAuthorizedAlways }; |
kCLAuthorizationStatusNotDetermined -> [0] 한번도 인증 요청을 안했을 경우. 사용자는 아직 이 앱이 […]