我如何在安装期间/在应用程序启动之前为 React Native 应用程序请求权限?

How do I request permissions during installation / before app starts for a React Native app?

我希望用户在安装期间/应用开始之前授予权限,而不是在应用 运行 时被提示。目前,我请求在 Android 版本的应用程序上进行粗略定位和麦克风访问,并在 IOS 版本的应用程序上请求 BLE 和麦克风访问权限。

这是不可能的,根据 Android 文档,只有当 android 版本低于 Marshmallow(即 < SDK 23)时,您才能在安装时请求权限。如果 android 版本为 marshmallow 或更高版本,则将在 运行 时询问权限,您无法更改它。

If the device is running Android 6.0 (API level 23) or higher, and the app's targetSdkVersion is 23 or higher, the app requests permissions from the user at run-time. The user can revoke the permissions at any time, so the app needs to check whether it has the permissions every time it accesses permission-protected APIs. For more information about requesting permissions in your app, see the Working with System Permissions training guide.

If the device is running Android 5.1.1 (API level 22) or lower, or the app's targetSdkVersion is 22 or lower, the system asks the user to grant the permissions when the user installs the app. If you add a new permission to an updated version of the app, the system asks the user to grant that permission when the user updates the app. Once the user installs the app, the only way they can revoke the permission is by uninstalling the app.

https://developer.android.com/guide/topics/permissions/requesting.html

对于iOS也是如此,在运行时请求权限,从iOS开始就是这样 9.我不确定[=21之前的流程是什么=] 9.