• 카테고리

    질문 & 답변
  • 세부 분야

    모바일 앱 개발

  • 해결 여부

    해결됨

android환경에서 usePermissions 훅 사용시 에러납니다..ㅜㅜ

24.03.18 00:51 작성 조회수 115

1

usePermissions훅 사용시 에러가 납니다. android환경입니다. 코드랑 에러 올리겠습니다.구글에 먼저 검색해도 잘 모르겠어서 질문드립니다.import {useEffect} from 'react'; import {Alert, Linking, Platform} from 'react-native'; import {check, PERMISSIONS, request, RESULTS} from 'react-native-permissions'; function usePermissions() { // 권한 관련 useEffect(() => { if (Platform.OS === 'android') { //정확한 위치권한 check(PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION) .then(result => { console.log('check location', result); if (result === RESULTS.DENIED) { return request(PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION); } else if (result === RESULTS.BLOCKED) { Alert.alert( '이 앱은 위치 권한 허용이 필요합니다.', '앱 설정 화면을 열어서 항상 허용으로 바꿔주세요.', //밑에 배열은 버튼을 의미한다. [ { text: '네', //Linking.openSettings는 핸드폰 설정을 열어준다. onPress: () => Linking.openSettings(), }, { text: '아니오', onPress: () => console.log('No Pressed'), style: 'cancel', }, ], ); } }) .catch(console.error); } else if (Platform.OS === 'ios') { check(PERMISSIONS.IOS.LOCATION_ALWAYS) .then(result => { if (result === RESULTS.BLOCKED || result === RESULTS.DENIED) { Alert.alert( '이 앱은 백그라운드 위치 권한 허용이 필요합니다.', '앱 설정 화면을 열어서 항상 허용으로 바꿔주세요.', [ { text: '네', onPress: () => Linking.openSettings(), }, { text: '아니오', onPress: () => console.log('No Pressed'), style: 'cancel', }, ], ); } }) .catch(console.error); } if (Platform.OS === 'android') { //카메라 권한 check(PERMISSIONS.ANDROID.CAMERA) .then(result => { if (result === RESULTS.DENIED || result === RESULTS.GRANTED) { return request(PERMISSIONS.ANDROID.CAMERA); } else { console.log(result); throw new Error('카메라 지원 안 함'); } }) .catch(console.error); } else { check(PERMISSIONS.IOS.CAMERA) .then(result => { if ( result === RESULTS.DENIED || result === RESULTS.LIMITED || result === RESULTS.GRANTED ) { return request(PERMISSIONS.IOS.CAMERA); } else { console.log(result); throw new Error('카메라 지원 안 함'); } }) .catch(console.error); } }, []); } export default usePermissions; 에러메세지 텍스트입니다.
Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNPermissions' could not be found. Verify that a module by this name is registered in the native binary., js engine: hermes at AppInner (http://10.0.2.2:8081/index.bundle//&platform=android&dev=true&minify=false&app=com.mh.fooddeliveryapp&modulesOnly=false&runModule=true:131130:86) at Provider (http://10.0.2.2:8081/index.bundle//&platform=android&dev=true&minify=false&app=com.mh.fooddeliveryapp&modulesOnly=false&runModule=true:130801:22) at App at RCTView at View (http://10.0.2.2:8081/index.bundle//&platform=android&dev=true&minify=false&app=com.mh.fooddeliveryapp&modulesOnly=false&runModule=true:59410:43) at RCTView at View (http://10.0.2.2:8081/index.bundle//&platform=android&dev=true&minify=false&app=com.mh.fooddeliveryapp&modulesOnly=false&runModule=true:59410:43) at AppContainer (http://10.0.2.2:8081/index.bundle//&platform=android&dev=true&minify=false&app=com.mh.fooddeliveryapp&modulesOnly=false&runModule=true:59254:36) at FoodDeliveryApp(RootComponent) (http://10.0.2.2:8081/index.bundle//&platform=android&dev=true&minify=false&app=com.mh.fooddeliveryapp&modulesOnly=false&runModule=true:107936:28) ERROR TypeError: Cannot read property 'check' of undefinedThis error is located at: in AppInner (created by App) in Provider (created by App) in App in RCTView (created by View) in View (created by AppContainer) in RCTView (created by View) in View (created by AppContainer) in AppContainer in FoodDeliveryApp(RootComponent), js engine: hermes ERROR TypeError: Cannot read property 'check' of undefinedThis error is located at: in AppInner (created by App) in Provider (created by App) in App in RCTView (created by View) in View (created by AppContainer) in RCTView (created by View) in View (created by AppContainer) in AppContainer in FoodDeliveryApp(RootComponent), js engine: hermes

답변 2

·

답변을 작성해보세요.

0

전민혁님의 프로필

전민혁

질문자

2024.03.18

아 react-native-permissions 삭제하고 깃헙 코드로 --save넣어서 다시 설치했더니 해결되었습니다 답변 감사합니다!
글작성시엔 포매팅이 되어있었는데 여기선 안되어있네요..다음부턴 확인하고 조심하겠습니다!

0

코드 포매팅 해주세요.

RN 몇 버전이신가요? 설치 과정 중에 문제가 생긴 걸로 보여서 다시 설치하는 수밖에 없어보입니다.

https://github.com/zoontek/react-native-permissions?tab=readme-ov-file#android-1

이 부분을 수동으로 진행해야 할 수도 있습니다.