WeChat applet anti-video recording screenshot ios+android

iOS screenshot has not been solved yet

Android video recording screenshot code

Can be written in onshow

 // 安卓防止截屏录屏
    if (/android/i.test(wx.getSystemInfoSync().system)&&wx.setVisualEffectOnCapture) {
    
    
      wx.setVisualEffectOnCapture({
    
    
        visualEffect: 'hidden',
        complete: function (res) {
    
    
          // wx.showToast({
    
    
          //   title: '成功',
          // })
        }
      })
    }

But it should be noted that you must not only enable monitoring, but also uninstall it.

  onHide() {
    
    
    //  页面隐藏和销毁时需要释放防截屏录屏设置
    // 安卓
    if (wx.setVisualEffectOnCapture) {
    
    
      wx.setVisualEffectOnCapture({
    
    
        visualEffect: 'none',
        complete: function (res) {
    
    }
      })
    }

  },
   onUnload() {
    
    
    //  页面隐藏和销毁时需要释放防截屏录屏设置
    if (wx.setVisualEffectOnCapture) {
    
    
      wx.setVisualEffectOnCapture({
    
    
        visualEffect: 'none',
        complete: function (res) {
    
    }
      })
    }

ios anti-video recording

  onLoad(options) {
    
    
    //跨屏幕防止ios录频
    if (/ios/i.test(wx.getSystemInfoSync().system)&&wx.getScreenRecordingState) {
    
    
    // res.state的值有两种情况 on(正在录屏) | off(没有开始录屏)
      wx.getScreenRecordingState({
    
    
        success: res => {
    
    
          if (res.state != 'off') {
    
    
            that.setData({
    
    
              isShow: false//这里我对页面进行了遮挡处理
            })
          } else {
    
    
            that.setData({
    
    
              isShow: true
            })
          }
        }
      })
    }
    // 在当前页面点击录频
    if (/ios/i.test(wx.getSystemInfoSync().system)&&wx.onScreenRecordingStateChanged) {
    
    
    //	res.state的值有两种情况 start(开始录屏) | stop(结束录屏)
      wx.onScreenRecordingStateChanged(res => {
    
    
        if (res.state == 'start') {
    
    
          that.setData({
    
    
            isShow: false//这里我对页面进行了遮挡处理
          })
        
        } else {
    
    
          that.setData({
    
    
            isShow: true
          })
        }
      })
    }
  },

Of course you have to uninstall it here too

 onHide() {
    
    
    //  页面隐藏和销毁时需要释放防截屏录屏设置
    // ios
    if (wx.offScreenRecordingStateChanged) {
    
    
      // 取消录屏监听事件
      wx.offScreenRecordingStateChanged()
    }

  },
   onUnload() {
    
    
    //  页面隐藏和销毁时需要释放防截屏录屏设置
    // ios
    if (wx.offScreenRecordingStateChanged) {
    
    
      // 取消录屏监听事件
      wx.offScreenRecordingStateChanged()
    }

  },

Guess you like

Origin blog.csdn.net/Yannnnnm/article/details/130554859