当前位置:   article > 正文

uniapp 安卓,ios 相机权限,华为审核被拒解决方案_安卓开发 华为相机权限被拒

安卓开发 华为相机权限被拒

背景:上架华为被拒了 

        1.您的应用在运行时,未同步告知权限申请的使用目的,向用户索取(相机、存储)等权限,不符合华为应用市场审核标准。
测试步骤:点击我的-投诉反馈-上传附件-拍摄/从相册选择,申请相机、存储权限。点击我的钱包-充值-上传转款凭证-拍摄/从相册选择,申请相机、存储权限。

【文献参考】App权限判断和提示 - DCloud 插件市场

解决方案:permission.js 和getAuth.js

permission.js 完整代码

  1. var isIos
  2. // #ifdef APP-PLUS
  3. isIos = (plus.os.name == "iOS")
  4. // #endif
  5. // 判断推送权限是否开启
  6. function judgeIosPermissionPush() {
  7. var result = false;
  8. var UIApplication = plus.ios.import("UIApplication");
  9. var app = UIApplication.sharedApplication();
  10. var enabledTypes = 0;
  11. if (app.currentUserNotificationSettings) {
  12. var settings = app.currentUserNotificationSettings();
  13. enabledTypes = settings.plusGetAttribute("types");
  14. console.log("enabledTypes1:" + enabledTypes);
  15. if (enabledTypes == 0) {
  16. console.log("推送权限没有开启");
  17. } else {
  18. result = true;
  19. console.log("已经开启推送功能!")
  20. }
  21. plus.ios.deleteObject(settings);
  22. } else {
  23. enabledTypes = app.enabledRemoteNotificationTypes();
  24. if (enabledTypes == 0) {
  25. console.log("推送权限没有开启!");
  26. } else {
  27. result = true;
  28. console.log("已经开启推送功能!")
  29. }
  30. console.log("enabledTypes2:" + enabledTypes);
  31. }
  32. plus.ios.deleteObject(app);
  33. plus.ios.deleteObject(UIApplication);
  34. return result;
  35. }
  36. // 判断定位权限是否开启
  37. function judgeIosPermissionLocation() {
  38. var result = false;
  39. var cllocationManger = plus.ios.import("CLLocationManager");
  40. var status = cllocationManger.authorizationStatus();
  41. result = (status != 2)
  42. console.log("定位权限开启:" + result);
  43. // 以下代码判断了手机设备的定位是否关闭,推荐另行使用方法 checkSystemEnableLocation
  44. /* var enable = cllocationManger.locationServicesEnabled();
  45. var status = cllocationManger.authorizationStatus();
  46. console.log("enable:" + enable);
  47. console.log("status:" + status);
  48. if (enable && status != 2) {
  49. result = true;
  50. console.log("手机定位服务已开启且已授予定位权限");
  51. } else {
  52. console.log("手机系统的定位没有打开或未给予定位权限");
  53. } */
  54. plus.ios.deleteObject(cllocationManger);
  55. return result;
  56. }
  57. // 判断麦克风权限是否开启
  58. function judgeIosPermissionRecord() {
  59. var result = false;
  60. var avaudiosession = plus.ios.import("AVAudioSession");
  61. var avaudio = avaudiosession.sharedInstance();
  62. var permissionStatus = avaudio.recordPermission();
  63. console.log("permissionStatus:" + permissionStatus);
  64. if (permissionStatus == 1684369017 || permissionStatus == 1970168948) {
  65. console.log("麦克风权限没有开启");
  66. } else {
  67. result = true;
  68. console.log("麦克风权限已经开启");
  69. }
  70. plus.ios.deleteObject(avaudiosession);
  71. return result;
  72. }
  73. // 判断相机权限是否开启
  74. function judgeIosPermissionCamera() {
  75. var result = false;
  76. var AVCaptureDevice = plus.ios.import("AVCaptureDevice");
  77. var authStatus = AVCaptureDevice.authorizationStatusForMediaType('vide');
  78. console.log("authStatus:" + authStatus);
  79. if (authStatus == 3) {
  80. result = true;
  81. console.log("相机权限已经开启");
  82. } else {
  83. console.log("相机权限没有开启");
  84. }
  85. plus.ios.deleteObject(AVCaptureDevice);
  86. return result;
  87. }
  88. // 判断相册权限是否开启
  89. function judgeIosPermissionPhotoLibrary() {
  90. var result = false;
  91. var PHPhotoLibrary = plus.ios.import("PHPhotoLibrary");
  92. var authStatus = PHPhotoLibrary.authorizationStatus();
  93. console.log("authStatus:" + authStatus);
  94. if (authStatus == 3) {
  95. result = true;
  96. console.log("相册权限已经开启");
  97. } else {
  98. console.log("相册权限没有开启");
  99. }
  100. plus.ios.deleteObject(PHPhotoLibrary);
  101. return result;
  102. }
  103. // 判断通讯录权限是否开启
  104. function judgeIosPermissionContact() {
  105. var result = false;
  106. var CNContactStore = plus.ios.import("CNContactStore");
  107. var cnAuthStatus = CNContactStore.authorizationStatusForEntityType(0);
  108. if (cnAuthStatus == 3) {
  109. result = true;
  110. console.log("通讯录权限已经开启");
  111. } else {
  112. console.log("通讯录权限没有开启");
  113. }
  114. plus.ios.deleteObject(CNContactStore);
  115. return result;
  116. }
  117. // 判断日历权限是否开启
  118. function judgeIosPermissionCalendar() {
  119. var result = false;
  120. var EKEventStore = plus.ios.import("EKEventStore");
  121. var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(0);
  122. if (ekAuthStatus == 3) {
  123. result = true;
  124. console.log("日历权限已经开启");
  125. } else {
  126. console.log("日历权限没有开启");
  127. }
  128. plus.ios.deleteObject(EKEventStore);
  129. return result;
  130. }
  131. // 判断备忘录权限是否开启
  132. function judgeIosPermissionMemo() {
  133. var result = false;
  134. var EKEventStore = plus.ios.import("EKEventStore");
  135. var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(1);
  136. if (ekAuthStatus == 3) {
  137. result = true;
  138. console.log("备忘录权限已经开启");
  139. } else {
  140. console.log("备忘录权限没有开启");
  141. }
  142. plus.ios.deleteObject(EKEventStore);
  143. return result;
  144. }
  145. // Android权限查询
  146. function requestAndroidPermission(permissionID) {
  147. return new Promise((resolve, reject) => {
  148. plus.android.requestPermissions(
  149. permissionID.split(","),
  150. // [permissionID], // 理论上支持多个权限同时查询,但实际上本函数封装只处理了一个权限的情况。有需要的可自行扩展封装
  151. function(resultObj) {
  152. var result = 0;
  153. for (var i = 0; i < resultObj.granted.length; i++) {
  154. var grantedPermission = resultObj.granted[i];
  155. console.log('已获取的权限:' + grantedPermission);
  156. result = 1
  157. }
  158. for (var i = 0; i < resultObj.deniedPresent.length; i++) {
  159. var deniedPresentPermission = resultObj.deniedPresent[i];
  160. console.log('拒绝本次申请的权限:' + deniedPresentPermission);
  161. result = 0
  162. }
  163. for (var i = 0; i < resultObj.deniedAlways.length; i++) {
  164. var deniedAlwaysPermission = resultObj.deniedAlways[i];
  165. console.log('永久拒绝申请的权限:' + deniedAlwaysPermission);
  166. result = -1
  167. }
  168. resolve(result);
  169. // 若所需权限被拒绝,则打开APP设置界面,可以在APP设置界面打开相应权限
  170. // if (result != 1) {
  171. // gotoAppPermissionSetting()
  172. // }
  173. },
  174. function(error) {
  175. console.log('申请权限错误:' + error.code + " = " + error.message);
  176. resolve({
  177. code: error.code,
  178. message: error.message
  179. });
  180. }
  181. );
  182. });
  183. }
  184. // 使用一个方法,根据参数判断权限
  185. function judgeIosPermission(permissionID) {
  186. if (permissionID == "location") {
  187. return judgeIosPermissionLocation()
  188. } else if (permissionID == "camera") {
  189. return judgeIosPermissionCamera()
  190. } else if (permissionID == "photoLibrary") {
  191. return judgeIosPermissionPhotoLibrary()
  192. } else if (permissionID == "record") {
  193. return judgeIosPermissionRecord()
  194. } else if (permissionID == "push") {
  195. return judgeIosPermissionPush()
  196. } else if (permissionID == "contact") {
  197. return judgeIosPermissionContact()
  198. } else if (permissionID == "calendar") {
  199. return judgeIosPermissionCalendar()
  200. } else if (permissionID == "memo") {
  201. return judgeIosPermissionMemo()
  202. }
  203. return false;
  204. }
  205. // 跳转到**应用**的权限页面
  206. function gotoAppPermissionSetting() {
  207. if (isIos) {
  208. var UIApplication = plus.ios.import("UIApplication");
  209. var application2 = UIApplication.sharedApplication();
  210. var NSURL2 = plus.ios.import("NSURL");
  211. // var setting2 = NSURL2.URLWithString("prefs:root=LOCATION_SERVICES");
  212. var setting2 = NSURL2.URLWithString("app-settings:");
  213. application2.openURL(setting2);
  214. plus.ios.deleteObject(setting2);
  215. plus.ios.deleteObject(NSURL2);
  216. plus.ios.deleteObject(application2);
  217. } else {
  218. // console.log(plus.device.vendor);
  219. var Intent = plus.android.importClass("android.content.Intent");
  220. var Settings = plus.android.importClass("android.provider.Settings");
  221. var Uri = plus.android.importClass("android.net.Uri");
  222. var mainActivity = plus.android.runtimeMainActivity();
  223. var intent = new Intent();
  224. intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
  225. var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
  226. intent.setData(uri);
  227. mainActivity.startActivity(intent);
  228. }
  229. }
  230. // 检查系统的设备服务是否开启
  231. // var checkSystemEnableLocation = async function () {
  232. function checkSystemEnableLocation() {
  233. if (isIos) {
  234. var result = false;
  235. var cllocationManger = plus.ios.import("CLLocationManager");
  236. var result = cllocationManger.locationServicesEnabled();
  237. console.log("系统定位开启:" + result);
  238. plus.ios.deleteObject(cllocationManger);
  239. return result;
  240. } else {
  241. var context = plus.android.importClass("android.content.Context");
  242. var locationManager = plus.android.importClass("android.location.LocationManager");
  243. var main = plus.android.runtimeMainActivity();
  244. var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
  245. var result = mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER);
  246. console.log("系统定位开启:" + result);
  247. return result
  248. }
  249. }
  250. let permissionMap = {
  251. "android": {
  252. "CAMERA_EXTERNAL_STORAGE": {
  253. "name": "android.permission.READ_EXTERNAL_STORAGE,android.permission.WRITE_EXTERNAL_STORAGE,android.permission.CAMERA",
  254. "title": "相机/相册权限说明",
  255. "content": "便于您使用该功能上传您的图片/视频及用于更换头像、反馈问题、完善项目信息等场景中读取和写入相册和文件内容"
  256. },
  257. "CAMERA": {
  258. "name": "android.permission.CAMERA",
  259. "title": "相机权限说明",
  260. "content": "便于您使用该功能上传图片,用于更换头像、反馈问题、完善项目信息等场景中发送拍摄图片"
  261. },
  262. "EXTERNAL_STORAGE": {
  263. "name": "android.permission.READ_EXTERNAL_STORAGE,android.permission.WRITE_EXTERNAL_STORAGE",
  264. "title": "相册权限说明",
  265. "content": "便于您使用该功能上传您的照片/图片/视频及用于更换头像、反馈问题、完善项目信息等场景中读取和写入相册和文件内容"
  266. }
  267. },
  268. "ios": {}
  269. }
  270. let view = null;
  271. function showViewDesc(permission) {
  272. let plat = isIos ? "ios" : "android";
  273. view = new plus.nativeObj.View('per-modal', {
  274. top: '0px',
  275. left: '0px',
  276. width: '100%',
  277. backgroundColor: 'rgba(0,0,0,0.2)',
  278. //opacity: '.9'
  279. })
  280. view.drawRect({
  281. color: '#fff',
  282. radius: '5px'
  283. }, {
  284. top: '30px',
  285. left: '5%',
  286. width: '90%',
  287. height: "100px",
  288. })
  289. view.drawText(permissionMap[plat][permission]["title"], {
  290. top: '40px',
  291. left: "8%",
  292. height: "30px"
  293. }, {
  294. align: "left",
  295. color: "#000",
  296. }, {
  297. onClick: function(e) {
  298. console.log(e);
  299. }
  300. })
  301. view.drawText(permissionMap[plat][permission]["content"], {
  302. top: '65px',
  303. height: "60px",
  304. left: "8%",
  305. width: "84%"
  306. }, {
  307. whiteSpace: 'normal',
  308. size: "14px",
  309. align: "left",
  310. color: "#656563"
  311. })
  312. view.show()
  313. }
  314. function premissionCheck(permission) {
  315. return new Promise(async (resolve, reject) => {
  316. let plat = isIos ? "ios" : "android";
  317. if (isIos) { // ios
  318. // const camera = permission.judgeIosPermission("camera");//判断ios是否给予摄像头权限
  319. // //ios相册没权限,系统会自动弹出授权框
  320. // //let photoLibrary = permission.judgeIosPermission("photoLibrary");//判断ios是否给予相册权限
  321. // if(camera){
  322. // resolve();
  323. // }else{
  324. // reject('需要开启相机使用权限');
  325. // }
  326. resolve(1)
  327. } else { // android
  328. let permission_arr = permissionMap[plat][permission]["name"].split(",");
  329. let flag = true;
  330. for(let i = 0;i<permission_arr.length;i++) {
  331. let status = plus.navigator.checkPermission(permission_arr[i]);
  332. if(status == "undetermined") {
  333. flag = false;
  334. }
  335. }
  336. console.log("flag", flag)
  337. if (flag == false) { // 未完全授权
  338. showViewDesc(permission);
  339. requestAndroidPermission(permissionMap[plat][permission]["name"]).then((res) => {
  340. view.close();
  341. if (res == -1) {
  342. uni.showModal({
  343. title: '提示',
  344. content: '操作权限已被拒绝,请手动前往设置',
  345. confirmText: "立即设置",
  346. success: (res) => {
  347. if (res.confirm) {
  348. gotoAppPermissionSetting()
  349. }
  350. }
  351. })
  352. }
  353. resolve(res)
  354. })
  355. } else {
  356. resolve(1)
  357. }
  358. }
  359. })
  360. }
  361. module.exports = {
  362. judgeIosPermission: judgeIosPermission,
  363. requestAndroidPermission: requestAndroidPermission,
  364. checkSystemEnableLocation: checkSystemEnableLocation,
  365. gotoAppPermissionSetting: gotoAppPermissionSetting,
  366. premissionCheck: premissionCheck
  367. }

getAuth.js完整代码

  1. import permision from "@/js_sdk/wa-permission/permission.js"
  2. /**
  3. * 获取手机摄像头和图册权限
  4. * */
  5. const cameraAuthority = () => {
  6. return new Promise(async (rel, rej) => {
  7. var platform = uni.getSystemInfoSync().platform || 'android';
  8. if (platform == 'ios') {
  9. let camera = permision.judgeIosPermission("camera");//判断ios是否给予摄像头权限
  10. //ios相册没权限,系统会自动弹出授权框
  11. //let photoLibrary = permision.judgeIosPermission("photoLibrary");//判断ios是否给予相册权限
  12. if (camera) {
  13. rel();
  14. } else {
  15. rej('需要开启相机使用权限');
  16. }
  17. } else {
  18. // console.log('安卓')
  19. let camera = await permision.requestAndroidPermission("android.permission.CAMERA");//判断安卓是否给予摄像头权限
  20. let photoLibrary = await permision.requestAndroidPermission("android.permission.READ_EXTERNAL_STORAGE");//判断安卓是否给予相册权限
  21. console.log('安卓',camera,photoLibrary)
  22. // if (camera == 0 || photoLibrary == 0) {
  23. // rej('请同时开启相机和相册的使用权限');
  24. // } else if (camera == -1 || photoLibrary == -1) {
  25. // //永久拒绝
  26. // rej(false)
  27. // } else {
  28. // rel();
  29. // }
  30. }
  31. })
  32. }
  33. /**
  34. * 限安卓
  35. * 是否打开了手机定位
  36. * */
  37. const adressOpen = () => {
  38. return permision.checkSystemEnableLocation();
  39. }
  40. /**
  41. * 限安卓
  42. * 获取位置信息权限
  43. * */
  44. const adressAuthority = () => {
  45. return new Promise(async (rel, rej) => {
  46. let adress = await permision.requestAndroidPermission("android.permission.ACCESS_FINE_LOCATION");//判断安卓是否有获取位置信息权限
  47. if (adress == 0) {
  48. rej('请开启定位权限');
  49. } else if (adress == -1) {
  50. //永久拒绝
  51. rej(false)
  52. } else {
  53. rel();
  54. }
  55. })
  56. }
  57. /**
  58. * 限安卓
  59. * 获取拨打电话权限
  60. * */
  61. const cellPhoneAuthority = () => {
  62. return new Promise(async (rel, rej) => {
  63. let adress = await permision.requestAndroidPermission("android.permission.CALL_PHONE");//拨打电话权限
  64. if (adress == 0) {
  65. rej('请开启拨打电话权限');
  66. } else if (adress == -1) {
  67. //永久拒绝
  68. rej(false)
  69. } else {
  70. rel();
  71. }
  72. })
  73. }
  74. /**
  75. * 跳转到手机开启权限的界面
  76. * */
  77. const permissionSetting = () => {
  78. permision.gotoAppPermissionSetting();
  79. }
  80. export {
  81. cameraAuthority,
  82. permissionSetting,
  83. adressAuthority,
  84. adressOpen,
  85. cellPhoneAuthority
  86. }

调用:

  1. <template>
  2. <view class="uploadImg">
  3. <view class="upload" @tap="selectImg" v-else-if="!is_limit"
  4. :style="url.length > 0 ? 'margin-bottom:20rpx' : ''">
  5. <uni-icons type="camera-filled" color="#999" size="18" class="currentIcon"> </uni-icons>
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. const app = getApp();
  11. import { cameraAuthority, permissionSetting } from "@/static/js/getAuth.js";
  12. import permision from "@/js_sdk/wa-permission/permission.js";
  13. export default {
  14. props: {
  15. zb_file_show: {
  16. type: Boolean,
  17. default: false,
  18. },
  19. count: {
  20. type: Number,
  21. default: 10000
  22. },
  23. is_limit: {
  24. type: Boolean,
  25. default: false,
  26. }
  27. },
  28. data() {
  29. return {
  30. url: [],
  31. };
  32. },
  33. created() { },
  34. methods: {
  35. clearImg(index) {
  36. this.url.splice(index, 1);
  37. this.$emit('clearImg')
  38. },
  39. async selectImg() {
  40. // 文档参考 https://blog.csdn.net/m0_46978096/article/details/116784053
  41. let _this = this;
  42. let platform = uni.getSystemInfoSync().platform;
  43. /*#ifdef APP-PLUS*/
  44. console.log('APP端:', platform)
  45. const isIosTrue = uni.getStorageSync('iosFirstCamera'); //是不是第一次开启相机
  46. //ios要先调用一下功能后,设置的权限列表里才会有该权限 ios和android分开判断
  47. if (platform == 'ios') {
  48. if (isIosTrue == 'false') {
  49. console.log('不是第一次')
  50. cameraAuthority().then(e => {
  51. console.log(e,'then')
  52. _this.uploadImg();
  53. }).catch(e => {
  54. console.log(e, 'catch');
  55. uni.showModal({
  56. title: '提示',
  57. content: '请先开启相机权限',
  58. success: function (res) {
  59. if (res.confirm) {
  60. permissionSetting();
  61. }
  62. }
  63. });
  64. })
  65. } else {
  66. console.log('是第一次')
  67. uni.setStorageSync('iosFirstCamera', 'false'); //设为false就代表不是第一次开启相机
  68. _this.uploadImg();
  69. }
  70. } else {
  71. var result = await permision.premissionCheck("CAMERA_EXTERNAL_STORAGE");
  72. console.log(result,'result')
  73. if (result == 1) {
  74. // 此处处理各自业务 如:uni.chooseImage
  75. console.log('有权限');
  76. _this.uploadImg();
  77. }
  78. }
  79. /*#endif*/
  80. /*#ifdef MP*/
  81. console.log('微信小程序端')
  82. _this.uploadImg();
  83. /*#endif*/
  84. },
  85. uploadImg() {
  86. // 获取年月日
  87. let year = new Date().getFullYear();
  88. let month = new Date().getMonth() + 1;
  89. let day = new Date().getDate();
  90. month = month < 10 ? "0" + month : month;
  91. day = day < 10 ? "0" + day : day;
  92. var that = this;
  93. uni.chooseImage({
  94. sizeType: ["compressed"],
  95. success(response) {
  96. console.log('你的逻辑')
  97. },
  98. });
  99. },
  100. previewImage(index) {
  101. uni.previewImage({
  102. urls: this.url,
  103. current: index,
  104. });
  105. },
  106. previewImage1(data) {
  107. uni.previewImage({
  108. urls: data,
  109. });
  110. }
  111. },
  112. };
  113. </script>
  114. <style lang="less">
  115. .uploadImg {
  116. display: flex;
  117. align-items: center;
  118. justify-content: flex-start;
  119. flex-wrap: wrap;
  120. .exampleBox {
  121. position: relative;
  122. margin-right: 20rpx;
  123. width: 106rpx;
  124. height: 106rpx;
  125. .exampleText {
  126. position: absolute;
  127. bottom: 0;
  128. left: 0;
  129. right: 0;
  130. height: 40rpx;
  131. background: rgba(0, 0, 0, 0.5);
  132. color: #fff;
  133. text-align: center;
  134. font-size: 22rpx;
  135. font-weight: 400;
  136. }
  137. }
  138. .imgView {
  139. width: 106rpx;
  140. height: 106rpx;
  141. display: block;
  142. position: relative;
  143. margin-right: 20rpx;
  144. margin-bottom: 20rpx;
  145. image {
  146. display: block;
  147. width: 106rpx;
  148. height: 106rpx;
  149. }
  150. .currentIcon {
  151. position: absolute;
  152. top: -11px;
  153. right: -11px;
  154. }
  155. }
  156. .upload {
  157. width: 106rpx;
  158. height: 106rpx;
  159. border: 1px dashed #d1d1d1;
  160. display: flex;
  161. align-items: center;
  162. justify-content: center;
  163. box-sizing: border-box;
  164. }
  165. }
  166. </style>

ios 需要修改mainfest文件:

  1. /* ios打包配置 */
  2. "ios" : {
  3. "dSYMs" : false,
  4. "idfa" : false,
  5. "privacyDescription" : {
  6. // 可选,字符串类型,系统相册读取权限描述
  7. "NSPhotoLibraryUsageDescription" : "APP需要您的同意才能访问相册,以便于上传图片",
  8. //可选,字符串类型,系统相册写入权限描述
  9. "NSPhotoLibraryAddUsageDescription" : "APP需要您的同意才能添加图片,以便于上传图片",
  10. //可选,字符串类型,摄像头使用权限描述
  11. "NSCameraUsageDescription" : "APP需要您的同意才能访问相机,以便于上传图片,若不允许,您将无法使用上传功能"
  12. }
  13. },

运行效果:

video(10)

华为审核被拒,解决方案

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/684531
推荐阅读
  

闽ICP备14008679号