티스토리 뷰

[사용자 허가 받기]

iOS 앱에는 크게 두가지 종류의 위치 받아오는 방법이 있습니다. 

 

1. When In Use

 

 

* 기본적으로 앱을 사용중일때만 위치 정보를 받아오는 옵션입니다. 

백그라운드 상태로 전환 시, location usage indicator (파란색 위치정보 제공중) 가 뜨고, 백그라운드에서 돌게 됩니다.

 

 

앱을 켜고 있을 때만 gps를 쓴다면: locationMan.requestWhenInAuthorization()

Info.plist의 Information Property List의 딕셔너리에 key-value값 추가해주기

이 경우에는 키를 NSLocationWhenInUsageDescription으로 해야함

 

만약 특정 지역에 유저가 걸어 들어갔을 때 푸시를 띄워주고 싶다면

developer.apple.com/documentation/usernotifications/unlocationnotificationtrigger

다음 문서를 참고하면 된다. 

 

 

2. Always

*유저가 모르는 중에도 지속적으로 위치 정보를 제공받는 옵션입니다.

앱이 꺼져있으면, OS에서 앱을 켜고 위치 정보를 계속 제공해줍니다.  

 

  • Your app performs automated tasks during which a prompt might be inconvenient or undesirable. For example, if your app triggers automatic actions when the user enters a location, such as turning on the lights, your app may require Always authorization.
  • Your app records numerous locations throughout the day, such as for a diary app. The user may prefer to allow Always authorization so your app can record locations even when it’s not in use, and without prompting the user.

하루에도 수십번 콜 되거나, 유저에게 권한을 써도 되는지 묻는게 너무 귀찮은 일일때 사용된다. 

권한을 Always로 설정해도 유저는 When In Use로 설정할 수 있다. 그러니까 개발자는 항상 When In Use일 수도 있다는 생각을 하고 개발을 해야한다. 

OS마다 이를 핸들링 하는 방법이 다른데 iOS에서는 When in use and Always로 하면 된다. 

 

 


NamePrivacy - Location Always and When In Use Usage DescriptionType

String

 

 

Location Accuracy 설정

locationMan.desiredAccuracy = 

 

 

 

 

 

 

이런 에러가 뜨길래 Location When in usage도 추가해줬다

 

 

 

거리 필터 구성

locationMan.distanceFilter

 

 

 

 CLLocationManagerDelegate 델리게이트 함수들.

    // Region start
    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    
    }
    
    func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
        print("GPS Error => \(error.localizedDescription)")
    }

    func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
        // 애플리케이션의 위치 추적 허가 상태가 변경될 경우 호출
    }

 

위치 업데이트

locationMan.startUpdating

 

 

위치 정보

CLLocation 객체 형태

Latitude, Longtitude, Altitude, Horiziontal Accuracy, Altitude Accuracy

 

 

 

위치 정보를 받기 위해서 Core Location 프레임워크를 쓸거니까 import를 해줘야한다.

 

 

 

delegate 채택도 해주는거 잊지 마세요!

 

 

CLLocationManager 객체를 하나 생성해 줍니다. 

 

 

 

 

Info.plist에 권한 추가해주기

 

1, 2번밖에 못쓴다. 

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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 27 28 29 30 31
글 보관함