Flutter Plugin Yidun Alive Detect

易盾活体检测flutter原生插件版

Getting Started

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

iOS Quirks

  1. 易盾活体检测用到摄像头功能,请确保有摄像和网络权限
  2. 在工程的info.plist文件里设置相机权限
NSPhotoLibraryUsageDescriptionApp需要您的同意,才能访问相册NSCameraUsageDescriptionApp需要您的同意,才能访问相机
  1. 编译: 将引入SDK头文件的.m文件重命名为.mm文件 或者 在Xcode中找到TARGETS-->Build Setting-->Apple Clang - Language-->Compile Source As在这个选项中选择 Objective-C++

  2. ios编译需安装pod环境。配置好开发者账号即可编译

  3. app接入活体设置(如权限设置等)请参考易盾文档

Android Quirks

1.易盾活体检测用到摄像头功能,请确保有摄像和网络权限 2.需要ndk能力,请在local.properties中配置ndk.dir

  1. 预览高度不要随意设置,请遵守大部分相机支持的预览高宽比,3:4或9:16
  2. 如果想在android设置预览的容器形状,请修改preview_layout.xml

活体接入

集成

在pubspec.yaml中添加 ``js dependencies: alive_flutter_plugin: ^xxx稳定版

### 配置依赖
在flutter工程对应的android/app/build.gradle 文件的android域中添加
``js
  repositories {
          flatDir {
              dirs project(':alive_flutter_plugin').file('libs')
          }
      }

初始化

  final AliveFlutterPlugin aliveFlutterPlugin = new AliveFlutterPlugin(); // 初始化对象
  
   aliveFlutterPlugin.init("请输入您的业务id", 40);
 

开始检测

   aliveFlutterPlugin.startLiveDetect().then((value) {
      /**
       * action表示返回的动作,动作状态表示:0——正面,1——右转,2——左转,3——张嘴,4——眨眼。
       */
      var actions = value["actions"];
      setState(() {
        this.action = actions;
        if (actions) {
          _result = "初始化成功$actions";
        } else {
          _result = "初始化失败$actions";
        }
      });
    });

停止检测

  aliveFlutterPlugin.stopLiveDetect();

释放资源(Android特有)

  aliveFlutterPlugin.destroy();

检测状态监听

   eventChannel.receiveBroadcastStream().listen(_onData, onError: _onError);
   
   void _onData(response) {
    if (response is Map) {
      setState(() {
        var type = response["type"];
        if (type == "checking") {
          _currentStep = response["currentStep"];
          _result = response["message"];
        } else if (type == "checked") {
          _result = response["message"];
          _currentStep = 0;
          stopLive();
        } else if (type == "exception") {
          _result = response["message"];
        }
      });
    }
  }

动作类型映射

var actions = value["actions"]; {
  '0': '正视前方',
	'1': '向右转头',
	'2': '向左转头',
	'3': '张嘴动作',
	'4': '眨眼动作',
};

简单示例app

cordova-yidun-alive-detect-demo for a complete working Cordova example for Android and iOS platforms.

Libraries

alive_flutter_plugin