Applet open the recording function (using wepy)

1. Check to get permission to record the recording obtain permission ---

onLoad(options, data) {
    this.judgeRecord().then(res=>{
        if(res==true) {
            this.recordInit = true;
            this.$apply();
        }
    })
    this.$apply();
}

  

. 1  judgeRecord () {
 2              return  new new Promise ( function (Resolve, Reject) {
 . 3                  wx.getSetting ({
 . 4                      Success (RES) {
 . 5                          IF (! Res.authSetting [ 'scope.record' ]) {
 . 6                              IF (RES. authSetting [ 'scope.record'] == undefined) {
 . 7                                  wx.authorize ({
 . 8                                      scope: 'scope.record' ,
 . 9                                      Success () {
 10                                          // user has agreed to use the applet recording function, subsequent calls wx.startRecord Interface does not popups asking 
11                                         // wx.startRecord () 
12 is                                          Resolve ( to true )
 13 is                                      },
 14                                      Fail () {
 15                                          Resolve ( to false )
 16                                      }
 . 17                                  })
 18 is                              } the else {
 . 19                                  wx.showModal ({
 20 is                                      title: 'recording permission request authorization' ,
 twenty one                                     content: 'You need to get the permission of the recording, please confirm the authorization' ,
 22                                      Success: function (RES) {
 23                                          IF (res.cancel) {
 24-                                              wx.showToast ({
 25                                                  title: 'deny authorization' ,
 26                                                  icon: 'none ' ,
 27                                                  DURATION: 1000
 28                                              })
 29                                              Resolve ( to false )
 30                                         } else if (res.confirm) {
31                                             wx.openSetting({
32                                                 success: function (dataAu) {
33                                                     if (dataAu.authSetting["scope.record"] == true) {
34                                                         wx.showToast({
35                                                             title: '授权成功',
36                                                             icon: 'success',
37                                                             DURATION: 1000
 38 is                                                          })
 39                                                          Resolve ( to true )
 40                                                          // sublicense, wx.getLocation the calling the API 
41 is                                                      } the else {
 42 is                                                          wx.showToast ({
 43 is                                                              title: 'Authorization Failed' ,
 44 is                                                              icon: 'none' ,
 45                                                             duration: 1000
46                                                         })
47                                                         resolve(false)
48                                                     }
49                                                 }
50                                             })
51                                         }
52                                     }
53                                 })
54                             }
55 
56                         }else{
57                             resolve(true)
58                         }
59                     }
60                 });
61             })
62 
63         }            

2. Initial Load If the user denies authorization, where required recording operation continues to call the authorization

onTouchStart(e) {
                this.$apply();
                if (!this.recordInit) {
                    this.judgeRecord();
                    return false;
                }
            },

  

Guess you like

Origin www.cnblogs.com/fairy62/p/12612064.html