From 71735bfc781933537fb03e8c0a858bce3bfa83ce Mon Sep 17 00:00:00 2001 From: Hyemin Heo Date: Thu, 15 Aug 2024 00:54:12 +0900 Subject: [PATCH] =?UTF-8?q?#79=20[Feat]=20=EB=B3=80=EA=B2=BD=EB=90=9C=20?= =?UTF-8?q?=EC=9C=84=EC=B9=98=20=EC=A0=95=EB=B3=B4=20=EC=A0=80=EC=9E=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Record/TodayWorkOut/LocationManager.swift | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Score/Score/Source/View/Record/TodayWorkOut/LocationManager.swift diff --git a/Score/Score/Source/View/Record/TodayWorkOut/LocationManager.swift b/Score/Score/Source/View/Record/TodayWorkOut/LocationManager.swift new file mode 100644 index 0000000..d030474 --- /dev/null +++ b/Score/Score/Source/View/Record/TodayWorkOut/LocationManager.swift @@ -0,0 +1,49 @@ +// +// LocationManager.swift +// Score +// +// Created by sole on 8/14/24. +// + +import CoreLocation +import os.log + +final class LocationManager: CLLocationManager { + private(set) var locations: [CLLocation] = [] + + override init() { + super.init() + self.delegate = self + } + + /// 위치 접근 권한이 없으면 위치 접근 권한을 요청하는 메서드입니다. + func requestAuthorization() { + switch self.authorizationStatus { + case .notDetermined: + self.requestWhenInUseAuthorization() + logger.debug("\(#function) 위치 접근 권한이 설정되지 않았습니다.") + case .restricted: + logger.debug("\(#function) 위치 접근 권한이 제한적으로 설정되었습니다.") + case .denied: + // go to setting + logger.debug("\(#function) 위치 접근 권한이 거부되었습니다.") + case .authorizedAlways: + logger.debug("\(#function) 위치 접근 권한이 항상 허용되었습니다.") + case .authorizedWhenInUse: + logger.debug("\(#function) 위치 접근 권한이 허용되었습니다.") + @unknown default: + logger.debug("\(#function) 알 수 없는 위치 권한입니다.") + } + } +} + +extension LocationManager: CLLocationManagerDelegate { + func locationManager( + _ manager: CLLocationManager, + didUpdateLocations locations: [CLLocation] + ) { + self.locations += locations + } +} + +fileprivate let logger = Logger(subsystem: "sole.Score", category: "LocationManager")