Skip to content

Commit

Permalink
Merge pull request #133 from dnd-side-project/feat/#122-RequestLocati…
Browse files Browse the repository at this point in the history
…on-Alert

Feat/#122 위치 권한 검사 및 권한설정 유도 팝업창 설정
  • Loading branch information
iowa329 authored Mar 10, 2024
2 parents 997f807 + 83d9dc1 commit 8f043b8
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 74 deletions.
16 changes: 10 additions & 6 deletions Reet-Place/Reet-Place.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
3CF3EAB82A3C29B9003B4DE2 /* CategoryDetailRestaurantList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CF3EAB72A3C29B9003B4DE2 /* CategoryDetailRestaurantList.swift */; };
3CF3EABA2A3C2A36003B4DE2 /* CategoryDetailBarList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CF3EAB92A3C2A36003B4DE2 /* CategoryDetailBarList.swift */; };
3CF3EABC2A3C2FA5003B4DE2 /* CategoryDetailHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CF3EABB2A3C2FA5003B4DE2 /* CategoryDetailHeaderView.swift */; };
3CF488AB2B836A1E00A3381C /* SearchPlaceAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CF488AA2B836A1E00A3381C /* SearchPlaceAction.swift */; };
3CF70D022A1BA82300523A74 /* LeftAlignedCollectionViewFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CF70D012A1BA82300523A74 /* LeftAlignedCollectionViewFlowLayout.swift */; };
3CFBC6FB2A6134C300540C7F /* SearchPlaceListResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CFBC6FA2A6134C300540C7F /* SearchPlaceListResponseModel.swift */; };
3CFBC6FD2A61368300540C7F /* SearchPlaceListRequestModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CFBC6FC2A61368300540C7F /* SearchPlaceListRequestModel.swift */; };
Expand Down Expand Up @@ -394,6 +395,7 @@
3CF3EAB72A3C29B9003B4DE2 /* CategoryDetailRestaurantList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryDetailRestaurantList.swift; sourceTree = "<group>"; };
3CF3EAB92A3C2A36003B4DE2 /* CategoryDetailBarList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryDetailBarList.swift; sourceTree = "<group>"; };
3CF3EABB2A3C2FA5003B4DE2 /* CategoryDetailHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryDetailHeaderView.swift; sourceTree = "<group>"; };
3CF488AA2B836A1E00A3381C /* SearchPlaceAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchPlaceAction.swift; sourceTree = "<group>"; };
3CF70D012A1BA82300523A74 /* LeftAlignedCollectionViewFlowLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeftAlignedCollectionViewFlowLayout.swift; sourceTree = "<group>"; };
3CFBC6FA2A6134C300540C7F /* SearchPlaceListResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchPlaceListResponseModel.swift; sourceTree = "<group>"; };
3CFBC6FC2A61368300540C7F /* SearchPlaceListRequestModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchPlaceListRequestModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1130,6 +1132,7 @@
3CE967472B4C0D27009F86FD /* DetailCategoryChipAction.swift */,
3CC9F07A2B7400BB00262B22 /* SearchHistoryAction.swift */,
3CC9F07C2B740B7300262B22 /* SearchHistoryListAction.swift */,
3CF488AA2B836A1E00A3381C /* SearchPlaceAction.swift */,
);
path = Protocols;
sourceTree = "<group>";
Expand Down Expand Up @@ -1509,6 +1512,7 @@
A4EFC09B299E6C9900B066AF /* LoginView.swift in Sources */,
3C2AED5E2990B3C200E36342 /* UIStackView+.swift in Sources */,
0EFE7C3F29B05D310051E72D /* ReetTextField.swift in Sources */,
3CF488AB2B836A1E00A3381C /* SearchPlaceAction.swift in Sources */,
0E05EFFF2A4C75C3008A20F4 /* OnboardingVC.swift in Sources */,
0E502B712A91968A002C71F2 /* BookmarkListRequestModel.swift in Sources */,
A4EFC099299E608500B066AF /* BaseNavigationViewController.swift in Sources */,
Expand Down Expand Up @@ -1749,9 +1753,9 @@
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = C9U8778A7W;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Reet-Place/Support/Info.plist";
INFOPLIST_KEY_NSLocationAlwaysAndWhenInUseUsageDescription = "사용자의 위치를 받습니다";
INFOPLIST_KEY_NSLocationAlwaysUsageDescription = "사용자의 위치를 받습니다";
INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "사용자의 위치를 받습니다";
INFOPLIST_KEY_NSLocationAlwaysAndWhenInUseUsageDescription = "원활한 지도 사용과 위치 기반 장소 검색을 위해 사용자의 위치 정보가 필요합니다.";
INFOPLIST_KEY_NSLocationAlwaysUsageDescription = "원활한 지도 사용과 위치 기반 장소 검색을 위해 사용자의 위치 정보가 필요합니다.";
INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "원활한 지도 사용과 위치 기반 장소 검색을 위해 사용자의 위치 정보가 필요합니다.";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen.storyboard;
INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait;
Expand Down Expand Up @@ -1791,9 +1795,9 @@
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = C9U8778A7W;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Reet-Place/Support/Info.plist";
INFOPLIST_KEY_NSLocationAlwaysAndWhenInUseUsageDescription = "사용자의 위치를 받습니다";
INFOPLIST_KEY_NSLocationAlwaysUsageDescription = "사용자의 위치를 받습니다";
INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "사용자의 위치를 받습니다";
INFOPLIST_KEY_NSLocationAlwaysAndWhenInUseUsageDescription = "원활한 지도 사용과 위치 기반 장소 검색을 위해 사용자의 위치 정보가 필요합니다.";
INFOPLIST_KEY_NSLocationAlwaysUsageDescription = "원활한 지도 사용과 위치 기반 장소 검색을 위해 사용자의 위치 정보가 필요합니다.";
INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "원활한 지도 사용과 위치 기반 장소 검색을 위해 사용자의 위치 정보가 필요합니다.";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen.storyboard;
INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,14 @@ StartReetPlace = "ReetPlace 시작하기";
DeleteBookmarkPopUpTitle = "북마크를 해제할까요?";
WithdrawalPopUpTitle = "정말 탈퇴하시겠어요?";
GoToLoginPopUpTitle = "로그인이 필요한 서비스에요!";
AuthorizeLocationPopUpTitle = "위치 권한설정";

DeleteBookmarkPopUpDesc = "북마크를 해제하시면,\n입력하셨던 내용이 전부 사라집니다.";
WithdrawalPopUpDesc = "탈퇴 이후 당신의 장소들은\n다시 복구되지 않아요.";
GoToLoginPopUpDesc = "로그인하고 장소들을 저장하고,\n나만의 지도를 채워보세요.";
AuthorizeLocationPopUpDesc = "원활한 지도 사용과 위치 기반 장소 검색을 위해 사용자의 위치 정보가 필요합니다.";

DeleteBookmarkPopUpConfirmTitle = "해제";
WithdrawalPopUpConfirmTitle = "탈퇴";
GoToLoginPopUpConfirmTitle = "로그인하기";
AuthorizeLocationPopUpConfirmTitle = "설정하기";
13 changes: 12 additions & 1 deletion Reet-Place/Reet-Place/Global/Enum/PopUpType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum PopUpType {
case deleteBookmark
case withdrawal
case goToLogin
case authorizeLocation
}

extension PopUpType {
Expand All @@ -22,6 +23,8 @@ extension PopUpType {
return "WithdrawalPopUpTitle".localized
case .goToLogin:
return "GoToLoginPopUpTitle".localized
case .authorizeLocation:
return "AuthorizeLocationPopUpTitle".localized
}
}

Expand All @@ -31,6 +34,8 @@ extension PopUpType {
return AssetFonts.h4.font
case .withdrawal, .goToLogin:
return AssetFonts.subtitle1.font
case .authorizeLocation:
return AssetFonts.subtitle1.font
}
}

Expand All @@ -42,6 +47,8 @@ extension PopUpType {
return "WithdrawalPopUpDesc".localized
case .goToLogin:
return "GoToLoginPopUpDesc".localized
case .authorizeLocation:
return "AuthorizeLocationPopUpDesc".localized
}
}

Expand All @@ -51,14 +58,16 @@ extension PopUpType {
return AssetFonts.body2.font
case .withdrawal, .goToLogin:
return AssetFonts.body1.font
case .authorizeLocation:
return AssetFonts.body1.font
}
}

var popUpDescColor: UIColor {
switch self {
case .deleteBookmark:
return AssetColors.error
case .withdrawal, .goToLogin:
case .withdrawal, .goToLogin, .authorizeLocation:
return AssetColors.black
}
}
Expand All @@ -71,6 +80,8 @@ extension PopUpType {
return "WithdrawalPopUpConfirmTitle".localized
case .goToLogin:
return "GoToLoginPopUpConfirmTitle".localized
case .authorizeLocation:
return "AuthorizeLocationPopUpConfirmTitle".localized
}
}

Expand Down
16 changes: 15 additions & 1 deletion Reet-Place/Reet-Place/Global/Extension/UIViewController+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ extension UIViewController {

}

/// Pop Up 노출
/// 릿플 스타일(ReetPopUp) 팝업창 노출
func showPopUp(popUpType: PopUpType, targetVC: UIViewController, confirmBtnAction: Selector) {
let popUpVC = ReetPopUp()

Expand Down Expand Up @@ -176,4 +176,18 @@ extension UIViewController {
return rootVC
}

/// 현재위치 권한설정 알람 팝업창 표시
func showPopUpAuthorizeLocation(){
showPopUp(popUpType: .authorizeLocation,
targetVC: self,
confirmBtnAction: #selector(openReetPlaceSettings))
}

/// 아이폰 설정 앱 - Reet-Place의 설정 화면으로 이동
@objc private func openReetPlaceSettings() {
if let appSetting = URL(string: UIApplication.openSettingsURLString) {
UIApplication.shared.open(appSetting)
}
}

}
16 changes: 16 additions & 0 deletions Reet-Place/Reet-Place/Global/Protocols/SearchPlaceAction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// SearchPlaceAction.swift
// Reet-Place
//
// Created by Kim HeeJae on 2024/02/17.
//

import UIKit
import CoreLocation

/// 장소 검색과 관련된 함수를 정의
protocol SearchPlaceAction {

func getLocationManager() -> CLLocationManager

}
22 changes: 22 additions & 0 deletions Reet-Place/Reet-Place/Global/Utils/KeychainManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import NMapsMap

final class KeychainManager {

Expand Down Expand Up @@ -130,6 +131,24 @@ extension KeychainManager {
}
}

/// 네이버 지도 상의 마지막 카메라 위치 값을 저장
func saveLastPosition(locationCoordinate: NMGLatLng) {
save(key: .lastPositionLat, value: locationCoordinate.lat.description)
save(key: .lastPositionLng, value: locationCoordinate.lng.description)
}

/// 사용자가 사용했던 네이버 지도 상의 마지막 카메라 위치 값을 조회
func readLastPosition() -> NMGLatLng? {
if let latitude = read(for: .lastPositionLat),
let longitude = read(for: .lastPositionLng),
let latitude = Double(latitude),
let longitude = Double(longitude) {
return NMGLatLng(lat: Double(latitude), lng: Double(longitude))
} else {
return nil
}
}

}

// MARK: - Keys
Expand All @@ -150,6 +169,9 @@ extension KeychainManager {
case userName
case memberID
case email

case lastPositionLat
case lastPositionLng
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ import RxDataSources
import Then
import SnapKit

/// 장소 검색과 관련된 함수를 정의
protocol SearchPlaceAction {
func getCurrentLocationCoordinate() -> CLLocationCoordinate2D?
}

class SearchVC: BaseViewController {

// MARK: - UI components
Expand Down Expand Up @@ -201,21 +196,27 @@ class SearchVC: BaseViewController {
}

private func requestSearchPlaceKeyword(requestPage: Int) {
if let curLocationCoordinate = delegateSearchPlaceAction?.getCurrentLocationCoordinate() {
if let keyword = searchTextField.text?.trimmingCharacters(in: .whitespaces), !keyword.isEmpty {
searchTextField.text = keyword

if !viewModel.output.isLoginUser {
CoreDataManager.shared.saveSearchKeyword(toSaveKeyword: keyword)
if let locationManager = delegateSearchPlaceAction?.getLocationManager() {
switch locationManager.authorizationStatus {
case .authorizedAlways, .authorizedWhenInUse:
if let keyword = searchTextField.text?.trimmingCharacters(in: .whitespaces), !keyword.isEmpty,
let coordinate = locationManager.location?.coordinate {
searchTextField.text = keyword

if !viewModel.output.isLoginUser {
CoreDataManager.shared.saveSearchKeyword(toSaveKeyword: keyword)
}

viewModel.requestSearchPlaceKeyword(placeKeyword: SearchPlaceKeywordRequestModel(lat: coordinate.latitude,
lng: coordinate.longitude,
placeKeword: keyword,
page: requestPage))
}

viewModel.requestSearchPlaceKeyword(placeKeyword: SearchPlaceKeywordRequestModel(lat: curLocationCoordinate.latitude,
lng: curLocationCoordinate.longitude,
placeKeword: keyword,
page: requestPage))
case .notDetermined:
locationManager.requestWhenInUseAuthorization()
default:
showPopUpAuthorizeLocation()
}
} else {
self.showErrorAlert("FailGetCurLocationCoordinate".localized)
}
}

Expand Down
Loading

0 comments on commit 8f043b8

Please sign in to comment.