From 5eff94ced06e3866a206b83148f340d0d2a15d77 Mon Sep 17 00:00:00 2001 From: goghrf Date: Thu, 5 Dec 2024 20:08:16 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9C=84=EC=B9=98=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=EC=A0=91=EA=B7=BC=20=EA=B6=8C=ED=95=9C=20=ED=97=88=EC=9A=A9?= =?UTF-8?q?=20=EC=97=AC=EB=B6=80=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ondoset/Ondoset.xcodeproj/project.pbxproj | 12 ++-- Ondoset/Ondoset/Common/Utils/Constants.swift | 9 +-- .../Common/Utils/LocationManager.swift | 71 ++++++++++++++----- Ondoset/Ondoset/Info.plist | 2 + .../Home/HomeMain/HomeMainView.swift | 2 +- .../Presentation/Initial/SplashView.swift | 52 ++++++++++---- 6 files changed, 107 insertions(+), 41 deletions(-) diff --git a/Ondoset/Ondoset.xcodeproj/project.pbxproj b/Ondoset/Ondoset.xcodeproj/project.pbxproj index 20c4ca5..f3f57cb 100644 --- a/Ondoset/Ondoset.xcodeproj/project.pbxproj +++ b/Ondoset/Ondoset.xcodeproj/project.pbxproj @@ -1286,13 +1286,13 @@ CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"Ondoset/Preview Content\""; - DEVELOPMENT_TEAM = 8T2JAAS967; + DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = Ondoset/Info.plist; INFOPLIST_KEY_NSCameraUsageDescription = "옷 사진 업로드 및 착장 사진 업로드 기능을 위해 카메라 접근 권한이 필요합니다."; - INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "착장 추천 및 업로드 기능을 위해 위치 정보 접근 권한이 필요합니다."; - INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "옷 사진 업로드 및 착장 사진 업로드 기능을 위해 앨범 접근 권한이 필요합니다."; + INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "착장 추천 및 업로드 기능을 위해 \n위치 정보 접근 권한이 필요합니다. \n허용하지 않으실 경우 \n서비스를 이용하실 수 없습니다."; + INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "사진 앨범에 접근할 수 있도록 접근 권한을 허용해주세요."; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; @@ -1327,13 +1327,13 @@ CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"Ondoset/Preview Content\""; - DEVELOPMENT_TEAM = 8T2JAAS967; + DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = Ondoset/Info.plist; INFOPLIST_KEY_NSCameraUsageDescription = "옷 사진 업로드 및 착장 사진 업로드 기능을 위해 카메라 접근 권한이 필요합니다."; - INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "착장 추천 및 업로드 기능을 위해 위치 정보 접근 권한이 필요합니다."; - INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "옷 사진 업로드 및 착장 사진 업로드 기능을 위해 앨범 접근 권한이 필요합니다."; + INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "착장 추천 및 업로드 기능을 위해 \n위치 정보 접근 권한이 필요합니다. \n허용하지 않으실 경우 \n서비스를 이용하실 수 없습니다."; + INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "사진 앨범에 접근할 수 있도록 접근 권한을 허용해주세요."; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; diff --git a/Ondoset/Ondoset/Common/Utils/Constants.swift b/Ondoset/Ondoset/Common/Utils/Constants.swift index 028db56..1a0e65c 100644 --- a/Ondoset/Ondoset/Common/Utils/Constants.swift +++ b/Ondoset/Ondoset/Common/Utils/Constants.swift @@ -14,14 +14,15 @@ import UIKit struct Constants { static let successResponseCode: String = "common_2000" - static var serverURL = isAvailableUnivURL ? univURL : ec2URL + static var serverURL = isDevelopURL ? developURL : ec2URL } -// 학과서버 죽으면 false, 쓸 수 있으면 true -let isAvailableUnivURL: Bool = false +let isDevelopURL: Bool = false -let univURL = "http://ceprj.gachon.ac.kr:60019" +// 개발용 +let developURL = "http://ec2-43-201-46-189.ap-northeast-2.compute.amazonaws.com:8080/member/test" //let ec2URL = "http://ec2-43-201-46-189.ap-northeast-2.compute.amazonaws.com:8080" +/// 운영용 let ec2URL = "https://ondoset.shop" diff --git a/Ondoset/Ondoset/Common/Utils/LocationManager.swift b/Ondoset/Ondoset/Common/Utils/LocationManager.swift index cf12e2c..f481ffe 100644 --- a/Ondoset/Ondoset/Common/Utils/LocationManager.swift +++ b/Ondoset/Ondoset/Common/Utils/LocationManager.swift @@ -10,27 +10,64 @@ import CoreLocation class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate { - private let locationManager = CLLocationManager() - @Published var currentLocation: CLLocationCoordinate2D? + public let locationManager = CLLocationManager() + @Published var currentLocation: CLLocationCoordinate2D? + @Published var authorizationStatus: CLAuthorizationStatus? + @Published var showSettingAlert = false - override init() { - super.init() - locationManager.delegate = self - locationManager.desiredAccuracy = kCLLocationAccuracyBest - locationManager.requestWhenInUseAuthorization() - } + override init() { + super.init() + locationManager.delegate = self + locationManager.desiredAccuracy = kCLLocationAccuracyBest + locationManager.requestWhenInUseAuthorization() + } - func requestLocation() { - locationManager.requestLocation() // 단일 위치 요청 - } + func requestLocation() { + locationManager.requestLocation() // 단일 위치 요청 + } - func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { - if let location = locations.last { - currentLocation = location.coordinate - } + func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { + if let location = locations.last { + currentLocation = location.coordinate } + } - func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { - print("Failed to find user's location: \(error.localizedDescription)") + func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { + print("Failed to find user's location: \(error.localizedDescription)") + } + + func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) { + switch manager.authorizationStatus { + case .notDetermined: + /// 아직 정해지지 않음 + print("notDetermined") + case .restricted: + print("restricted") + case .denied: + /// 허용 안함 + /// 사용자가 한 번 거부하면 반복적으로 물어볼 수 없습니다. + print("denied") + UserDefaults.standard.set(LocationAuthorizationType.denied.rawValue, forKey: "locationAuthorization") + showSettingAlert = true + case .authorizedAlways: + print("authorzedAlways") + case .authorizedWhenInUse: + /// 한 번 허용 & 앱을 사용하는 동안 허용 + print("authorizedWhenInUse") + UserDefaults.standard.set(LocationAuthorizationType.authorizedWhenInUse.rawValue, forKey: "locationAuthorization") + @unknown default: + print("default") } + } +} + +enum LocationAuthorizationType: String { + /// 아직 정해지지 않음 + case notDetermined + /// 허용 안 함 + case denied + /// 앱을 사용하는 동안 허용 + case authorizedWhenInUse + /// 한 번 허용 + case authorizedOnce } diff --git a/Ondoset/Ondoset/Info.plist b/Ondoset/Ondoset/Info.plist index cf8c929..2f5557a 100644 --- a/Ondoset/Ondoset/Info.plist +++ b/Ondoset/Ondoset/Info.plist @@ -14,5 +14,7 @@ Pretendard-SemiBold.otf Pretendard-Thin.otf + NSPhotoLibraryUsageDescription + 앱에서 사진을 선택하기 위해 접근 권한이 필요합니다. diff --git a/Ondoset/Ondoset/Presentation/Home/HomeMain/HomeMainView.swift b/Ondoset/Ondoset/Presentation/Home/HomeMain/HomeMainView.swift index 9c78a8b..e42b66d 100644 --- a/Ondoset/Ondoset/Presentation/Home/HomeMain/HomeMainView.swift +++ b/Ondoset/Ondoset/Presentation/Home/HomeMain/HomeMainView.swift @@ -49,7 +49,7 @@ struct HomeMainView: View { .onAppear(perform: { homeMainVM.homeViewDate = .now - locationManager.requestLocation() +// locationManager.requestLocation() if let location = locationManager.currentLocation { diff --git a/Ondoset/Ondoset/Presentation/Initial/SplashView.swift b/Ondoset/Ondoset/Presentation/Initial/SplashView.swift index 986e616..7f98d87 100644 --- a/Ondoset/Ondoset/Presentation/Initial/SplashView.swift +++ b/Ondoset/Ondoset/Presentation/Initial/SplashView.swift @@ -8,24 +8,23 @@ import SwiftUI struct SplashView: View { - - @State var isActive: Bool = false // 다음 화면 활성화 + @State var isActive: Bool = false @AppStorage("isLogin") var isLogin: Bool = false @AppStorage("isFirst") var isFirst: Bool = true + @StateObject var locationManager: LocationManager = LocationManager() + @AppStorage("locationAuthorization") var locationAuth: LocationAuthorizationType = .notDetermined + + init() { + UserDefaults.standard.register(defaults: ["locationAuthorization": LocationAuthorizationType.notDetermined.rawValue]) + } var body: some View { ZStack { - if !isLogin && isActive { SignInView() } else if isLogin && isActive { OndosetHome() -// } else if isLogin && isActive && !isFirst { -// OndosetHome() -// } else if isLogin && isActive && isFirst { -// OnboardingView() } else { - ZStack { Color(.main) VStack { @@ -38,15 +37,42 @@ struct SplashView: View { } } .onAppear { - - DispatchQueue.main.asyncAfter(deadline: .now() + 3) { + if locationAuth == .notDetermined { + locationManager.locationManager.requestWhenInUseAuthorization() + } else if locationAuth == .authorizedWhenInUse { + isActive = true + } + } + .onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in + let status = locationManager.locationManager.authorizationStatus + if status == .authorizedWhenInUse { + locationAuth = .authorizedWhenInUse isActive = true + } else if status == .denied { + locationAuth = .denied + locationManager.showSettingAlert = true } } + .alert(isPresented: $locationManager.showSettingAlert) { + Alert( + title: Text("위치 권한 필요"), + message: Text("위치 권한이 거부되었습니다. 위치 정보를 사용하려면 설정에서 권한을 허용해주세요."), + primaryButton: .default(Text("설정으로 이동"), action: { + if let appSetting = URL(string: UIApplication.openSettingsURLString) { + UIApplication.shared.open(appSetting) + } + }), + secondaryButton: .cancel(Text("취소"), action: { + if locationAuth == .denied { + locationManager.locationManager.requestWhenInUseAuthorization() + } + }) + ) + } .ignoresSafeArea() } } -#Preview { - SplashView() -} +//#Preview { +// SplashView(locationManager: LocationManager()) +//}