Home  >  Article  >  WeChat Applet  >  Solution to authorized photo album in mini program (with code)

Solution to authorized photo album in mini program (with code)

不言
不言Original
2018-08-21 17:09:556449browse

The content of this article is about the solution to authorized photo albums in the mini program (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Solutions to authorizing photo albums in mini programs:
1. First use wx.getSetting() to obtain the user's authorization. An authorization or authorization interface will pop up, where you need to decide whether to refuse. and allowed judgment.
2. If allowed, do the logic directly.
3. If rejected, you have to display the authorized button

<button type=&#39;primary&#39;  size=&#39;mini&#39;  open-type="openSetting"   bindopensetting=&#39;handleSetting&#39;   >
去授权</button>;
4、在打开
handleSetting: function (e) {
    let that = this;    // 对用户的设置进行判断,如果没有授权,即使用户返回到保存页面,显示的也是“去授权”按钮;同意授权之后才显示保存按钮
    if (!e.detail.authSetting[&#39;scope.writePhotosAlbum&#39;]) {
      wx.showModal({
        title: &#39;警告&#39;,
        content: &#39;若不打开授权,则无法将图片保存在相册中!&#39;,
        showCancel: false
      })
      that.setData({
        saveImgBtnHidden: false,
        openSettingBtnHidden: true
      })
    } else {
      wx.showModal({
        title: &#39;提示&#39;,
        content: &#39;您已授权,赶紧将图片保存在相册中吧!&#39;,
        showCancel: false
      })
      that.setData({
        saveImgBtnHidden: true,
        openSettingBtnHidden: false
      })
    }
  },

Related recommendations:

How to clear the default styles of buttons and scroll bars in mini programs (code)

WeChat applet example code: pull up and load more implementation methods

The above is the detailed content of Solution to authorized photo album in mini program (with code). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn