react native - IOS no permission handler detected 에러 해결

nearworld·2023년 5월 23일
0

개발 일지

목록 보기
7/7

앱이 카메라 접근에 대해 허가를 받아야하는 상황입니다.

react-native-permissions 설치

npm i react-native-permissions

Info.plist 에 속성 추가

경로: ios/MyApp/Info.plist
info.plist 파일을 열고 아래 키 밸류 값을 추가해줍니다.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	...
    <key>NSCameraUsageDescription</key>
    <string>앱에서 카메라에 접근 요청합니다.</string>
</dict>
</plist>

package.json

reactNativePermissionIOS 항목 추가

{
  "name": "livepickstar",
  "version": "0.0.1",
  "private": true,
  "scripts": {
  	...
  },
  "dependencies": {
  	...
  },
  "reactNativePermissionsIOS": [ 
  	"Camera"
  ]
}

위 설정들이 모두 끝났다면 아래 명령어들을 순차적으로 실행

  • npm ci
  • npx react-native setup-ios-permissions
  • npx pod-install ios

위 명령어들을 실행했다면 메트로 실행 후 IOS 시뮬레이터를 실행해준다.

pod install 자동으로 실행하는 방법

package.json

{
  ...
  "scripts": {
    "postinstall": "npx react-native setup-ios-permissions && npx pod-install ios"
  }
}

postinstall은 라이브러리 설치 후 자동으로 실행되게 할 커맨드를 등록하는 속성이다.
위 설정이 있다면 npm inpm ci나 라이브러리 설치후 postinstall 에 등록된 커맨드가 자동으로 실행된다.

앞으로는 npm i, npm ci만 해주면 pod install을 수동으로 해 줄 필요가 없다.

profile
깃허브: https://github.com/nearworld

0개의 댓글