开发过程中不免会遇到各种个样的权限问题,我常用的权限中这里做一个备忘
一、Android常用权限:AndroidManifest.xml中
1、http请求权限:
android:usesCleartextTraffic="true" // application内
2、照相权限:
<uses-permission android:name="android.permission.CAMERA"/>
3、写权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
4、定位权限:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
其中照相和写权限仅仅这样声明是不可以的,还得在代码中动态申请权限
#include “permissions.h”
QtAndroid::PermissionResult r = QtAndroid::checkPermission(“android.permission.WRITE_EXTERNAL_STORAGE”);
if(r == QtAndroid::PermissionResult::Denied) {
QtAndroid::requestPermissionsSync( QStringList() << “android.permission.WRITE_EXTERNAL_STORAGE” );
r = QtAndroid::checkPermission(“android.permission.WRITE_EXTERNAL_STORAGE”);
if(r == QtAndroid::PermissionResult::Denied) {
return false;
}
}
QtAndroid::PermissionResult p = QtAndroid::checkPermission(“android.permission.CAMERA”);
if(p == QtAndroid::PermissionResult::Denied) {
QtAndroid::requestPermissionsSync( QStringList() << “android.permission.CAMERA” );
p = QtAndroid::checkPermission(“android.permission.CAMERA”);
if(p == QtAndroid::PermissionResult::Denied) {
return false;
}
}
permissions文件下载链接:https://download.csdn.net/download/nikon800/14998764
二、ios常用权限:
Xcode的权限设置
info.plist文件:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>6.0</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>6.0</string>
<key>NSCameraUsageDescription</key>
<string>6.0</string>
<key>NSLocationUsageDescription</key>
<string>6.0</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>6.0</string>