react-native-permissions 在 react-native expo 项目中返回 RNPermissions null
react-native-permissions returning RNPermissions null in react-native expo project
我是 Expo 的新手,我不知道这里有什么问题,我对 Android 已经足够好了,我正在尝试根据代码的需要使用 react-native-qrcode-scanner in a newly created blank react-native expo project. I haven't touched anything inside the project, just created a brand new project and I get an error saying RNPermissions is null
. I think its telling to pass details about my android App, can anyone help me with how to start this? I am using react-native-permissions QR Code Scanner,我卸载了依赖项中的所有内容,只留下了这些:
"dependencies": {
"expo": "~36.0.0",
"react": "~16.9.0",
"react-dom": "~16.9.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz",
"react-native-permissions": "^2.0.2",
"react-native-web": "~0.11.7"
}
所以 App.js 中只有基本的欢迎回复消息,如下所示:
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { check, PERMISSIONS, RESULTS } from 'react-native-permissions';
class App extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
export default App;
这是 app.json 文件:
{
"expo": {
"name": "App1",
"slug": "App1",
"privacy": "public",
"sdkVersion": "36.0.0",
"platforms": [
"ios",
"android",
"web"
],
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
}
}
}
根据您在 App.js 上分享的内容,您还没有使用 react-native-permissions
中的任何功能
您需要获得设备所有者的许可才能使用相机。一些你可能遗漏的东西,你想检查以下内容:
对于Android
- AndroidManifest.xml - 您是否已请求所需的权限。 You may refer to this.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
- 确保您已链接库
对于iOS
- 您需要将以下内容附加到您的 Info.plist
<key>NSCameraUsageDescription</key>
<string>Our app need your permission to use your camera phone</string>
- 确保您已链接库
- Pod 安装在 iOS 文件夹中(对于 React Native >= 0.60)Follow the instruction given here
- 运行
react-native link
在项目根目录(对于 React Native <0.60)
此包 react-native-qrcode-scanner 建议使用 React Native 相机,并且需要 linking。如果您使用的是 expo ,您将无法 link 因为 expo 不允许 link 图书馆。因此,如果您打算使用相同的库,那么首先从 expo 弹出以响应本机,然后尝试使用它,因为您无法访问 linking 库。
如果你想在 expo 中实现,那么 expo 有自己的 barcodescanner ,请在下面查看。 expo barcode scanner。它有一个漂亮的文档。请务必阅读。
希望对您有所帮助。有疑问请随意
我是 Expo 的新手,我不知道这里有什么问题,我对 Android 已经足够好了,我正在尝试根据代码的需要使用 react-native-qrcode-scanner in a newly created blank react-native expo project. I haven't touched anything inside the project, just created a brand new project and I get an error saying RNPermissions is null
. I think its telling to pass details about my android App, can anyone help me with how to start this? I am using react-native-permissions QR Code Scanner,我卸载了依赖项中的所有内容,只留下了这些:
"dependencies": {
"expo": "~36.0.0",
"react": "~16.9.0",
"react-dom": "~16.9.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz",
"react-native-permissions": "^2.0.2",
"react-native-web": "~0.11.7"
}
所以 App.js 中只有基本的欢迎回复消息,如下所示:
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { check, PERMISSIONS, RESULTS } from 'react-native-permissions';
class App extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
export default App;
这是 app.json 文件:
{
"expo": {
"name": "App1",
"slug": "App1",
"privacy": "public",
"sdkVersion": "36.0.0",
"platforms": [
"ios",
"android",
"web"
],
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
}
}
}
根据您在 App.js 上分享的内容,您还没有使用 react-native-permissions
您需要获得设备所有者的许可才能使用相机。一些你可能遗漏的东西,你想检查以下内容:
对于Android
- AndroidManifest.xml - 您是否已请求所需的权限。 You may refer to this.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
- 确保您已链接库
对于iOS
- 您需要将以下内容附加到您的 Info.plist
<key>NSCameraUsageDescription</key>
<string>Our app need your permission to use your camera phone</string>
- 确保您已链接库
- Pod 安装在 iOS 文件夹中(对于 React Native >= 0.60)Follow the instruction given here
- 运行
react-native link
在项目根目录(对于 React Native <0.60)
此包 react-native-qrcode-scanner 建议使用 React Native 相机,并且需要 linking。如果您使用的是 expo ,您将无法 link 因为 expo 不允许 link 图书馆。因此,如果您打算使用相同的库,那么首先从 expo 弹出以响应本机,然后尝试使用它,因为您无法访问 linking 库。
如果你想在 expo 中实现,那么 expo 有自己的 barcodescanner ,请在下面查看。 expo barcode scanner。它有一个漂亮的文档。请务必阅读。
希望对您有所帮助。有疑问请随意