uniapp - 检查用户是否授权、如果拒绝授权提供提示框,用户可以在设置界面中打开权限


最近在用uniapp 开发微信小程序 vue + vuex + vue-cli3 + hbuilderx 

 1 export function checkForAuthorization(scope){
 2     return new Promise((resolve,reject)=>{
 3         uni.getSetting({
 4             success(res) {
 5                 console.log(res.authSetting)
 6                 if (!res.authSetting[scope]) {
 7                     uni.authorize({
 8                         scope,
 9                         success() {
10                             resolve()
11                         },
12                         fail() {
13                             uni.hideLoading();
14                             uni.showModal({
15                                 title: '温馨提示',
16                                 content: '您已拒绝授权,是否去设置打开?',
17                                 confirmText: "确认",
18                                 cancelText: "取消",
19                                 success: function(res) {
20                                     // console.log(res);
21                                     if (res.confirm) {
22                                         uni.hideLoading();
23                                         uni.openSetting({
24                                             success: (res) => {
25                                                 res.authSetting[scope] = true
26                                                 resolve()
27                                             }
28                                         });
29                                     } else {
30                                         reject({errMsg:'用户拒绝授权'})
31                                     }
32                                 },
33                                 fail(res) {
34                                     reject(res)
35                                 }
36                             });
37                      
38                         }
39                     })
40                 } else {
41                     resolve()
42                 }
43             },
44             fail(res) {
45                 reject(res)
46             }
47         })
48     })

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM