개발일지/스파르타내일배움단 웹, 앱개발 공부

4주차 앱개발 개발일지

developer soohyung park 2022. 5. 28. 17:24

뭔가 고난의 연속이였다. 

제대로된 개념을 잡지 못해서 node, yarn, expo를 몇번이나 재설치 후 정상적으로 코딩을 진행하였다.

 

eperm: 퍼미션 에러가 계속나서 구글링을 계속했고 처음부터 재설치를 하였으며 패키지 설치시 글로벌 설치외에는 해당 폴더의 node_module 폴더에 설치가 된다는 것을 꼭 숙지하길 바란다. 그리고 혹시 문제가 된다면 속성>보안 권한설정 및 폴더의 읽기전용을 해제해 보자.

 

외부API사용법, 파이어베이스 사용법(스토리지, 리얼타임데이터베이스- 읽기, 쓰기)을 통해서 화면을 이동하며 데이터베이스에서 저장된 내용을 가져오거나 수정, 삭제를 하게되었다.

 

날씨 API 제공 https://openweathermap.org/api 회원 가입 후 사용

 

Weather API - OpenWeatherMap

Please, sign up to use our fast and easy-to-work weather APIs. As a start to use OpenWeather products, we recommend our One Call API 3.0. For more functionality, please consider our products, which are included in professional collections.

openweathermap.org

expo 위치정보 사용 패키지

expo install expo-location

expo 위치정보 가져오기

const getLocation = async () => {
    //수많은 로직중에 에러가 발생하면
    //해당 에러를 포착하여 로직을 멈추고,에러를 해결하기 위한 catch 영역 로직이 실행
    try {
      //자바스크립트 함수의 실행순서를 고정하기 위해 쓰는 async,await
      await Location.requestPermissionsAsync();
      const locationData= await Location.getCurrentPositionAsync();
      console.log(locationData)

    } catch (error) {
      //혹시나 위치를 못가져올 경우를 대비해서, 안내를 준비합니다
      Alert.alert("위치를 찾을 수가 없습니다.", "앱을 껏다 켜볼까요?");
    }
  }

api 도메인 형식으로 사용 패키지 axios 설치

yarn add axios

expo 위치정보로 날씨 가져오기

const getLocation = async () => {
    //수많은 로직중에 에러가 발생하면
    //해당 에러를 포착하여 로직을 멈추고,에러를 해결하기 위한 catch 영역 로직이 실행
    try {
      //자바스크립트 함수의 실행순서를 고정하기 위해 쓰는 async,await
      await Location.requestPermissionsAsync();
      const locationData= await Location.getCurrentPositionAsync();
      const latitude = locationData['coords']['latitude']
      const longitude = locationData['coords']['longitude']
      const API_KEY = "  -발급받은키- ";
      const result = await axios.get(
        `http://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&appid=${API_KEY}&units=metric`
      );

      console.log(result)

    } catch (error) {
      //혹시나 위치를 못가져올 경우를 대비해서, 안내를 준비합니다
      Alert.alert("위치를 찾을 수가 없습니다.", "앱을 껏다 켜볼까요?");
    }
  }

파이어베이스 패키지 설치

expo install firebase
//패키지 설치 및 파이어베이스 웹 프로젝트 생성 후 키 받아서 사용
//파이어 베이스 버전에 따른 오류가 빈번하니 도중에 문제생기면 버전다운필요함
반응형