# To grant authorization

Some interfaces require user authorization to be invoked. We divide these interfaces into multiple scope , the user selects the right to scope To carry out the authorization. When the authorization is given to a scope After that, all the corresponding interfaces can be used directly.

When such interfaces are invoked:

  • If the user has not accepted or refused this permission, the pop-up window will ask the user, and the user can call the interface after clicking on the consent.
  • Interface can be called directly if the user is authorized
  • If the user has declined authorization, a pop-up window does not appear, but goes directly to the interface fail Callback.Ask the developer to be compatible with scenarios where the user denies authorization.

# Get User Authorization Settings

Developers can use wx.getSetting Gets the user's current authorization status.

# Open the settings screen

The user can view the Mini Program settings interfaceUpper right corner - about - Upper right corner - Set up) to control the authorization status of the Mini Program.

Developers can call wx.openSetting Open the settings screen and guide the user to open the authorization.

# Initiate authorization requests in advance

Developers can use wx.authorize In the call requiring authorization API The authorization request is made to the user in advance.

# scope list

scope Correspondence interface describe
scope.userLocation wx.getLocation, wx.startLocationUpdate, MapContext.moveToLocation Precise geographic location
scope.userFuzzyLocation wx.getFuzzyLocation Fuzzy geographic location
scope.userLocationBackground wx.startLocationUpdateBackground Background positioning
scope.record live-pusherComponents, wx.startRecord, wx.joinVoIPChat, RecorderManager.start microphone
scope.camera CameraComponents, live-pusherComponents, wx.createVKSession camera
scope.bluetooth wx.openBluetoothAdapter, wx.createBLEPeripheralServer Bluetooth
scope.writePhotosAlbum wx.saveImageToPhotosAlbum, wx.saveVideoToPhotosAlbum Add to Photo Album
scope.addPhoneContact wx.addPhoneContact Add to Contacts
scope.addPhoneCalendar wx.addPhoneRepeatCalendar, [wx.addPhoneCalendar ]((wx.addPhoneCalendar )) Add to Calendar
scope.werun wx.getWeRunData WeRun Movement Steps
scope.address wx.chooseAddress Address (deauthorized, can call the corresponding interface directly)
scope.invoiceTitle wx.chooseInvoiceTitle Invoice header (disauthorized, can call the corresponding interface directly)
scope.invoice wx.chooseInvoice Get the invoice (deauthorized, you can call the corresponding interface directly)
scope.userInfo [wx.getUserInfo ]((wx.getUserInfo )) User information (the Mini Program has been recycled, use theAvatar Nickname FillThe game can continue to be played.

# Validity of authorization

Once the user explicitly agrees or rejects the authorization, the authorization relationship will be recorded in the background until the user takes the initiative to delete the Mini Program.

# Best practices

Only issue an authorization request to the user when there is a real need to use the authorization interface, and make it clear in the authorization request why you want to use the feature.

# Note

  1. Need authorization scope.userLocationscope.userLocationBackgroundscope.userFuzzyLocation When necessaryConfiguration Location Purpose Dxplaination
  2. The authorization pop-up will show the Mini Program in thePrivacy Protection Guidelines for Users of Mini ProgramsPlease fill in the instructions carefully.

# Background positioning

The developer first needs to declare in the ability to run in the backgroundBackground positioning

Android 8.0.0 , iOS 8.0.0 If the developer can support it. wx.authorize({scope: 'scope.userLocationBackground'}) Evoke the background to use the geolocation authorization window.

Below the above version, scope.userLocationBackground No pop-up alerts for users. In the settings page, the user needs to actively set the "location information" option to "use the Mini Program during and after leaving the Mini Program." Developers can do this by callingwx.openSetting, open the Settings page.

background-location