안녕하세요 3G입니다.
오늘은 어제 하던 것에 이어 3번 권한 승인에 따른 상태 처리를 완성했어요
솔직히,,, 왜 때문인지는 아직 잘 모르는 상태
일단 복붙으로 성공
차차 공부해보도록 해요
3. 권한 승인 상태 처리
// 위치 권한 상태 변경 시 호출되는 메서드
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
switch status {
case .authorizedWhenInUse, .authorizedAlways:
print("위치 권한 승인됨")
locationManager.startUpdatingLocation() // 위치 업데이트 시작
case .denied, .restricted:
print("위치 권한 거부됨")
default:
break
}
}
// 위치가 업데이트될 때 호출되는 메서드
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let location = locations.last else { return }
print("현재 위치: \(location.coordinate.latitude), \(location.coordinate.longitude)")
// 현재 위치로 카메라 이동 (필요한 경우 주석 해제)
// let currentPosition = NMGLatLng(lat: location.coordinate.latitude, lng: location.coordinate.longitude)
// let cameraUpdate = NMFCameraUpdate(scrollTo: currentPosition)
// mapView.mapView.moveCamera(cameraUpdate)
}
// 위치 업데이트 실패 시 호출되는 메서드
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("위치 업데이트 실패: \(error.localizedDescription)")
}
// NMFMapViewCameraDelegate 메서드 (필요한 경우 구현)
func mapView(_ mapView: NMFMapView, cameraDidChangeByReason reason: Int, animated: Bool) {
print("카메라 변경 이유: \(reason), 애니메이션: \(animated)")
}
'iOS > 흡구오디' 카테고리의 다른 글
[앱 만들기] 지도 첫 화면 지정 | 사용자 위치 권한 요청하고 처리하기 (0) | 2024.12.24 |
---|---|
[앱 만들기] 클론에 실패하여 다시 시작 그리고 복습 (1) | 2024.12.23 |
[앱 만들기]내 현재 위치 표시하기...를 시작하기 (1) | 2024.12.16 |
[앱 만들기] xcode 네이버 지도 api 연결해서 지도 띄우기 (1) | 2024.12.05 |
[앱 개발] 앱 개발을 시작해보자! (7) | 2024.12.03 |