Connect 개발 회고 네이버맵스 (2)

이건준·2022년 8월 4일
0

1. 개발 회고 1회차 문제 해결

  • 커스텀뷰, 마커, 주소검색에 따른 검색결과 셋 중 어느걸 선택하냐에 따라 다른 데이터를 FloatingPanel에 띄어주는 부분을 enum타입을 만들어 각각 그에 맞는 셀 형식을 갖도록 하였다
enum FloatingType { // 어떤 데이터를 담은 플로팅파넬을 띄어줄지
    case who // Select customView
    case study // Select marker
    case searchResult // Search address
}

class MapFloatingPanelViewController: UIViewController {
    
    let floatingType: FloatingType
    
    private lazy var connectCollectionView: UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .vertical
        layout.sectionInset = UIEdgeInsets(top: 25, left: 15, bottom: 10, right: 15)
        let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
        return collectionView
    }()
    
    init(floatingType: FloatingType) {
        self.floatingType = floatingType
        super.init(nibName: nil, bundle: nil)
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        switch floatingType {
            case .who:
                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: WhoCollectionViewCell.identifier, for: indexPath) as? WhoCollectionViewCell ?? WhoCollectionViewCell()
                cell.configureUI(with: "")
                return cell
            case .study:
                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: StudyCollectionViewCell.identifer, for: indexPath) as? StudyCollectionViewCell ?? StudyCollectionViewCell()
                cell.configureUI(with: "")
                return cell
            case .searchResult:
                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: SearchAddressCollectionViewCell.identifier, for: indexPath) as? SearchAddressCollectionViewCell ?? SearchAddressCollectionViewCell()
                cell.configureUI(with: "안녕하세요")
                cell.backgroundColor = .systemBlue
//                cell.frame = CGRect(x: 0, y: 0, width: collectionView.frame.width, height: 50)
                return cell
        }
    }
  • FloatingType을 만들어 init함수로 받게 하였고 해당 타입에 따라 서로 다른 분기처리를 해주었다

2. 네이버맵스 현재위치 불러오기

  • 네이버맵스에서 현재위치를 불러오기위해선 크게 2가지 방법이 있다
    첫번째로 커스텀버튼을 만들어서 해당 mapView.positionMode를 이용하기
    두번째로 NMFNaverMapView에서 제공하는 currentLocationButton이용하기

  • 위 방법을 사용하면
    둘 다 흰 화면에 위치를 나타내는 이미지가 트래킹된다, 즉 우리가 생각했던 실제 위치를 트래킹하는 화면이 아닌 것이다

  • 이 부분에서 실제 위치를 가져와 표시해줄 수 있는 방법이 바로 CoreLocation을 이용하여 가져오는 방법이다

import CoreLocation

var locationManager = CLLocationManager()

self.locationManager.delegate = self
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
        self.locationManager.requestWhenInUseAuthorization()

        if CLLocationManager.locationServicesEnabled() {
            print("위치 서비스 On 상태")
            locationManager.startUpdatingLocation()
            print(locationManager.location?.coordinate)
        } else {
            print("위치 서비스 Off 상태")
        }

3. 네이버맵스 권한가져오기

  • 위 방법이 보통 네이버맵스를 이용해 현재위치를 표시하기위한 일반적인 방법이다
    우리가 앞에서 트래킹버튼을 실행하는것까지 하였는데 실제로 위 과정을 거치면 currentLocationButton은 클릭조차 되지않으며 커스텀버튼을 이용한 방법에서도 아무런 동작을 시행하지않는다

  • 우린 현재위치를 가져오기위하여 반드시 권한을 받아야하는데 이를 위한 것이 바로

  • 위 부분을 info.plist에 추가하는 것입니다

  • 많은 블로그들과 글들이 이렇게 표현합니다, 실제로 info.plist에 추가해야하는 경우 해당 key와 value를 손쉽게 삽입가능합니다

  • 그러나 저희 사이드 프로젝트에선 Tuist를 사용하였으며 key와 value를 직접 Dependencies파일에 넣어줘야했습니다, 그렇게 하니 아무런 권한허용알림창이 뜨지않았고 무슨 문제인지 전혀 알아차리지 못하였습니다

  • 그렇게 위 부분을 source code로 확인한 결과

    	<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    	<string></string>
    	<key>NSLocationWhenInUseUsageDescription</key>
    	<string>위치기반입니다.</string>
    	<key>NSLocationAlwaysUsageDescription</key>
    	<string>위치기반입니다.</string>
  • 위처럼 나와있습니다, 혹여 저와 같은 현상을 겪고 있다면 반드시 Privacy-~를 삽입하지말고 해당 키를 삽입하면 우리가 원하던 팝업창을 볼 수 있습니다

4. Connect 개발과정 중 해결하지 못한점

  • 현재 위치를 가져오는 과정에서 locationManager.requestWhenInUseAuthorization() 코드가 위 판업창을 띄어주는 코드이다
    헌데 지도화면이 띄어질때 한번 판업창을 띄어준 이후에 한번 더 판업창을 띄어주기위해 위 코드를 사용하는 과정에서 불가하다는것을 깨달았다

  • 위치권한판업창을 다시 띄어주는 방법을 찾아봐야할 것 같다

0개의 댓글