[React Native] react-native-permission 사용법
[환경] react-native: 0.61.5
https://github.com/react-native-community/react-native-permissions
react-native-community/react-native-permissions
An unified permissions API for React Native on iOS and Android - react-native-community/react-native-permissions
github.com
PHOTO_LIBRARY
(갤러리) 접근 권한 허용을 위해 오늘 쓸 라이브러리!
문서가 잘 정리되어 있어서 그대로 따라가겠음.
1) SetUp
$ npm install --save react-native-permissions
# --- or ---
$ yarn add react-native-permissions
[iOS]
Podfile에
pod 'Permission-Camera', :path => "#{permissions_path}/Camera.podspec"
추가 후
cd ios && pod install
ios/yourappname/Info.plist에도
<key>NSCameraUsageDescription</key>
<string>YOUR TEXT</string>
추가
2) Usage
import {PERMISSIONS, RESULTS, request} from 'react-native-permissions';
const askPermission = async () => {
try {
const result = await request(PERMISSIONS.IOS.PHOTO_LIBRARY);
if (result === RESULTS.GRANTED) {
// do something
}
} catch (error) {
console.log('askPermission', error);
}
};
이런 식으로 쓰고 싶은 카메라에 대해서 사용 가능!
3) error
돌려보자! 나는 이 에러를 만났다.
Should be one of: ()
그래서 이 에러를 만났을 때 어떻게 해야하는지도 친절히 알려줘서 그대로 따라했더니 됐다
// Clean up Xcode stale data with
npx react-native-clean-project --remove-iOS-build --remove-iOS-pods
4) 갤러리에서 사진 가져오기
https://coding-dahee.tistory.com/146
[React Native] 갤러리에서 사진 가져오기 (iOS)
갤러리에서 사진을 가져오려면 camera 권한이 필요함. 1) camera 권한 요청 https://coding-dahee.tistory.com/145 [React Native] react-native-permission 사용법 https://github.com/react-native-community/re..
coding-dahee.tistory.com
는 위 포스팅을 참고!