[TIL] RN Geolocation Service 설정하기

홍효정·2021년 8월 22일
0

TIL

목록 보기
40/40

❗️ React native Geolocation Service 기초설정 방법 정리입니다.

Install

GitHub - Agontuk/react-native-geolocation-service: React native geolocation service for iOS and android

# yarn
yarn add react-native-geolocation-service

# npm
npm install react-native-geolocation-service

RN 의 Geolocation 은 더이상 지원하지 않기 때문에 라이브러리를 설치하도록 합니다.

Setup

react-native-geolocation-service/setup.md at master · Agontuk/react-native-geolocation-service

geolocation 을 사용하려면 몇가지 설정이 필요합니다. readme 를 참고하여 설정하도록 합니다.

IOS

1. Linking

RN 버전이 6.0 보다 높다면 pod install 만으로 linking 을 대체 할 수 있습니다.

  1. cd ios
  2. pod install

2. Swift Support 허용

  1. Xcode 에서 프로젝트 폴더를 선택합니다.
  2. Ios 폴더에서 새로운 Swift 파일을 생성합니다. 이름은 아무것이나 상관없습니다. (File -> New -> File)
  3. Next 를 클릭하고 브리징 헤더를 생성할 것인지 묻는 메시지가 표시되면 클릭 하고 예라고 말합니다. (중요)

3. info.plist 수정

  1. ios > 프로젝트명 > info.plist 를 필요에 맞게 수정합니다.
  2. App 이 백그라운드에서도 위치정보를 가져올 필요가 없다면 첫번째 key 만 추가하고, 그렇지 않다면 모두 추가하도록 합니다.
<key>NSLocationWhenInUseUsageDescription</key>
<string>위치 정보 사용을 위해 권한 동의가 필요합니다.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>서비스 동작을 위해 위치 정보가 필요합니다</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>서비스 동작을 위해 위치 정보가 필요합니다</string>

Android

1. Linking

RN 버전이 6.0 보다 높다면 추가 설정이 필요하지 않습니다.

2. Permissions

  1. android > app > src > main > AndroidManifest.xml 에서 permission 을 추가합니다.
    (상단의 uses-permission ... 이 모여있는곳)
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
profile
HHJ velog 🍔

0개의 댓글