• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

我的博客我做主

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

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     })

 

作者:kitty20180903suzhou
出处:https://www.cnblogs.com/kitty-blog/
本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。

posted on 2020-09-27 15:11  kitty20180903suzhou  阅读(6942)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3