How WeChat Mini Programs Obtain User Authorization Again

Now I am making a small program with the function of map, and open the map by clicking the button. Calling the wx.getlocation() interface requires user authorization. If he is authorized, of course it is best to return a success, and there will be no problem. If he clicks Cancel and returns a fail, I turn on a positioning using the preset latitude and longitude. But if the user clicks back and clicks the button again to enter the map, there will be no response (the map can be reopened again if authorized at the beginning).

Is there any way to solve it, or how to re-acquire user authorization. After all, if you ask them to delete it and start over, it doesn't seem like such a good experience. . .

 

Method: A: Click the hidden stamp wx.openSetting(OBJECT) to re-invoke the applet authorization, the document now has [the following is the document content]

wx.openSetting(OBJECT)

 

Call up the client applet setting interface and return the operation result set by the user

Object parameter description:

Parameter type required description
success Function no The callback function of the successful interface call. For details of the returned content, please refer to the return parameter description.
fail Function no Callback function for interface call failure
complete Function no The callback function of the end of the interface call (the call will be executed if it succeeds or fails)

Description of parameters returned by success:

Parameter Type Description
authSetting Object User authorization result, where key is scope value and value is Bool value, indicating whether the user is allowed to authorize, see scope list for details

Sample code:

wx.openSetting({
  success: (res) => {
    /*
     * res.authSetting = {
     *   "scope.userInfo": true,
     *   "scope.userLocation": true
     * }
     */
  }
})

wx.getSetting(OBJECT)

 

Get the user's current settings

Object parameter description:

Parameter type required description
success Function no The callback function of the successful interface call. For details of the returned content, please refer to the return parameter description.
fail Function no Callback function for interface call failure
complete Function no The callback function of the end of the interface call (the call will be executed if it succeeds or fails)

Description of parameters returned by success:

Parameter Type Description
authSetting Object User authorization result, where key is scope value and value is Bool value, indicating whether the user is allowed to authorize, see scope list for details

Sample code:

wx.getSetting({
  success: (res) => {
    /*
     * res.authSetting = {
     *   "scope.userInfo": true,
     *   "scope.userLocation": true
     * }
     */
  }
})

 

 

 

 

 

  1. Map:function(){
  2.     wx.getLocation({
  3.       type: 'gcj02',
  4.       success: function(res){
  5.         // success
  6.         wx.openLocation({
  7.           latitude: res.latitude,
  8.           longitude: res.longitude,
  9.           scale: 28,      
  10.         })},
  11.       
  12.       fail: function(res){
  13.         // fail
  14.         wx.openLocation({
  15.           address: "Failed to obtain authorization to open the default location",
  16.         //I will hide the default location
  17.           latitude: XX.XX,
  18.           longitude: XX.XX,
  19.           scale: 28,      
  20.         },
  21.         wx.openSetting({
  22.           //request to get the location again
  23.         success: (res) => {}})
  24.         )},
  25.     })
  26.   }

Reprinted from: http://blog.csdn.net/telnet_pjc

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326313509&siteId=291194637