lizhiyu

初始化项目

Showing 37 changed files with 1412 additions and 0 deletions
  1 +# OSX
  2 +#
  3 +.DS_Store
  4 +
  5 +# Xcode
  6 +#
  7 +build/
  8 +*.pbxuser
  9 +!default.pbxuser
  10 +*.mode1v3
  11 +!default.mode1v3
  12 +*.mode2v3
  13 +!default.mode2v3
  14 +*.perspectivev3
  15 +!default.perspectivev3
  16 +xcuserdata
  17 +*.xccheckout
  18 +*.moved-aside
  19 +DerivedData
  20 +*.hmap
  21 +*.ipa
  22 +*.xcuserstate
  23 +project.xcworkspace
  24 +
  25 +# Android/IntelliJ
  26 +#
  27 +build/
  28 +.idea
  29 +.gradle
  30 +local.properties
  31 +*.iml
  32 +
  33 +# node.js
  34 +#
  35 +node_modules/
  36 +npm-debug.log
  37 +yarn-error.log
  38 +
  39 +# BUCK
  40 +buck-out/
  41 +\.buckd/
  42 +*.keystore
  43 +
  44 +# fastlane
  45 +#
  46 +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
  47 +# screenshots whenever they are needed.
  48 +# For more information about the recommended setup visit:
  49 +# https://docs.fastlane.tools/best-practices/source-control/
  50 +
  51 +*/fastlane/report.xml
  52 +*/fastlane/Preview.html
  53 +*/fastlane/screenshots
  54 +
  55 +# CocoaPods
  56 +Pods
  57 +
  58 +*.dSYM.zip
  1 +*.iml
  2 +.gradle
  3 +/local.properties
  4 +/.idea/workspace.xml
  5 +/.idea/libraries
  6 +.DS_Store
  7 +/build
  8 +/captures
  9 +.externalNativeBuild
  1 +
  2 +buildscript {
  3 + repositories {
  4 + jcenter()
  5 + }
  6 +
  7 + dependencies {
  8 + classpath 'com.android.tools.build:gradle:1.3.1'
  9 + }
  10 +}
  11 +
  12 +apply plugin: 'com.android.library'
  13 +
  14 +android {
  15 + compileSdkVersion 23
  16 + buildToolsVersion "23.0.1"
  17 +
  18 + defaultConfig {
  19 + minSdkVersion 16
  20 + targetSdkVersion 22
  21 + versionCode 1
  22 + versionName "1.0"
  23 + }
  24 + lintOptions {
  25 + abortOnError false
  26 + }
  27 +}
  28 +
  29 +repositories {
  30 + mavenCentral()
  31 +}
  32 +
  33 +dependencies {
  34 + compile 'com.facebook.react:react-native:+'
  35 + compile 'com.google.zxing:core:3.3.2'
  36 +}
  1 +# Project-wide Gradle settings.
  2 +
  3 +# IDE (e.g. Android Studio) users:
  4 +# Gradle settings configured through the IDE *will override*
  5 +# any settings specified in this file.
  6 +
  7 +# For more details on how to configure your build environment visit
  8 +# http://www.gradle.org/docs/current/userguide/build_environment.html
  9 +
  10 +# Specifies the JVM arguments used for the daemon process.
  11 +# The setting is particularly useful for tweaking memory settings.
  12 +org.gradle.jvmargs=-Xmx1536m
  13 +
  14 +# When configured, Gradle will run in incubating parallel mode.
  15 +# This option should only be used with decoupled projects. More details, visit
  16 +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
  17 +# org.gradle.parallel=true
No preview for this file type
  1 +#Wed Apr 18 16:16:41 CST 2018
  2 +distributionBase=GRADLE_USER_HOME
  3 +distributionPath=wrapper/dists
  4 +zipStoreBase=GRADLE_USER_HOME
  5 +zipStorePath=wrapper/dists
  6 +distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-all.zip
  1 +#!/usr/bin/env bash
  2 +
  3 +##############################################################################
  4 +##
  5 +## Gradle start up script for UN*X
  6 +##
  7 +##############################################################################
  8 +
  9 +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
  10 +DEFAULT_JVM_OPTS=""
  11 +
  12 +APP_NAME="Gradle"
  13 +APP_BASE_NAME=`basename "$0"`
  14 +
  15 +# Use the maximum available, or set MAX_FD != -1 to use that value.
  16 +MAX_FD="maximum"
  17 +
  18 +warn ( ) {
  19 + echo "$*"
  20 +}
  21 +
  22 +die ( ) {
  23 + echo
  24 + echo "$*"
  25 + echo
  26 + exit 1
  27 +}
  28 +
  29 +# OS specific support (must be 'true' or 'false').
  30 +cygwin=false
  31 +msys=false
  32 +darwin=false
  33 +case "`uname`" in
  34 + CYGWIN* )
  35 + cygwin=true
  36 + ;;
  37 + Darwin* )
  38 + darwin=true
  39 + ;;
  40 + MINGW* )
  41 + msys=true
  42 + ;;
  43 +esac
  44 +
  45 +# Attempt to set APP_HOME
  46 +# Resolve links: $0 may be a link
  47 +PRG="$0"
  48 +# Need this for relative symlinks.
  49 +while [ -h "$PRG" ] ; do
  50 + ls=`ls -ld "$PRG"`
  51 + link=`expr "$ls" : '.*-> \(.*\)$'`
  52 + if expr "$link" : '/.*' > /dev/null; then
  53 + PRG="$link"
  54 + else
  55 + PRG=`dirname "$PRG"`"/$link"
  56 + fi
  57 +done
  58 +SAVED="`pwd`"
  59 +cd "`dirname \"$PRG\"`/" >/dev/null
  60 +APP_HOME="`pwd -P`"
  61 +cd "$SAVED" >/dev/null
  62 +
  63 +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
  64 +
  65 +# Determine the Java command to use to start the JVM.
  66 +if [ -n "$JAVA_HOME" ] ; then
  67 + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
  68 + # IBM's JDK on AIX uses strange locations for the executables
  69 + JAVACMD="$JAVA_HOME/jre/sh/java"
  70 + else
  71 + JAVACMD="$JAVA_HOME/bin/java"
  72 + fi
  73 + if [ ! -x "$JAVACMD" ] ; then
  74 + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
  75 +
  76 +Please set the JAVA_HOME variable in your environment to match the
  77 +location of your Java installation."
  78 + fi
  79 +else
  80 + JAVACMD="java"
  81 + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
  82 +
  83 +Please set the JAVA_HOME variable in your environment to match the
  84 +location of your Java installation."
  85 +fi
  86 +
  87 +# Increase the maximum file descriptors if we can.
  88 +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
  89 + MAX_FD_LIMIT=`ulimit -H -n`
  90 + if [ $? -eq 0 ] ; then
  91 + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
  92 + MAX_FD="$MAX_FD_LIMIT"
  93 + fi
  94 + ulimit -n $MAX_FD
  95 + if [ $? -ne 0 ] ; then
  96 + warn "Could not set maximum file descriptor limit: $MAX_FD"
  97 + fi
  98 + else
  99 + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
  100 + fi
  101 +fi
  102 +
  103 +# For Darwin, add options to specify how the application appears in the dock
  104 +if $darwin; then
  105 + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
  106 +fi
  107 +
  108 +# For Cygwin, switch paths to Windows format before running java
  109 +if $cygwin ; then
  110 + APP_HOME=`cygpath --path --mixed "$APP_HOME"`
  111 + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
  112 + JAVACMD=`cygpath --unix "$JAVACMD"`
  113 +
  114 + # We build the pattern for arguments to be converted via cygpath
  115 + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
  116 + SEP=""
  117 + for dir in $ROOTDIRSRAW ; do
  118 + ROOTDIRS="$ROOTDIRS$SEP$dir"
  119 + SEP="|"
  120 + done
  121 + OURCYGPATTERN="(^($ROOTDIRS))"
  122 + # Add a user-defined pattern to the cygpath arguments
  123 + if [ "$GRADLE_CYGPATTERN" != "" ] ; then
  124 + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
  125 + fi
  126 + # Now convert the arguments - kludge to limit ourselves to /bin/sh
  127 + i=0
  128 + for arg in "$@" ; do
  129 + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
  130 + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
  131 +
  132 + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
  133 + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
  134 + else
  135 + eval `echo args$i`="\"$arg\""
  136 + fi
  137 + i=$((i+1))
  138 + done
  139 + case $i in
  140 + (0) set -- ;;
  141 + (1) set -- "$args0" ;;
  142 + (2) set -- "$args0" "$args1" ;;
  143 + (3) set -- "$args0" "$args1" "$args2" ;;
  144 + (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
  145 + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
  146 + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
  147 + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
  148 + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
  149 + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
  150 + esac
  151 +fi
  152 +
  153 +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
  154 +function splitJvmOpts() {
  155 + JVM_OPTS=("$@")
  156 +}
  157 +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
  158 +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
  159 +
  160 +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
  1 +@if "%DEBUG%" == "" @echo off
  2 +@rem ##########################################################################
  3 +@rem
  4 +@rem Gradle startup script for Windows
  5 +@rem
  6 +@rem ##########################################################################
  7 +
  8 +@rem Set local scope for the variables with windows NT shell
  9 +if "%OS%"=="Windows_NT" setlocal
  10 +
  11 +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
  12 +set DEFAULT_JVM_OPTS=
  13 +
  14 +set DIRNAME=%~dp0
  15 +if "%DIRNAME%" == "" set DIRNAME=.
  16 +set APP_BASE_NAME=%~n0
  17 +set APP_HOME=%DIRNAME%
  18 +
  19 +@rem Find java.exe
  20 +if defined JAVA_HOME goto findJavaFromJavaHome
  21 +
  22 +set JAVA_EXE=java.exe
  23 +%JAVA_EXE% -version >NUL 2>&1
  24 +if "%ERRORLEVEL%" == "0" goto init
  25 +
  26 +echo.
  27 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
  28 +echo.
  29 +echo Please set the JAVA_HOME variable in your environment to match the
  30 +echo location of your Java installation.
  31 +
  32 +goto fail
  33 +
  34 +:findJavaFromJavaHome
  35 +set JAVA_HOME=%JAVA_HOME:"=%
  36 +set JAVA_EXE=%JAVA_HOME%/bin/java.exe
  37 +
  38 +if exist "%JAVA_EXE%" goto init
  39 +
  40 +echo.
  41 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
  42 +echo.
  43 +echo Please set the JAVA_HOME variable in your environment to match the
  44 +echo location of your Java installation.
  45 +
  46 +goto fail
  47 +
  48 +:init
  49 +@rem Get command-line arguments, handling Windowz variants
  50 +
  51 +if not "%OS%" == "Windows_NT" goto win9xME_args
  52 +if "%@eval[2+2]" == "4" goto 4NT_args
  53 +
  54 +:win9xME_args
  55 +@rem Slurp the command line arguments.
  56 +set CMD_LINE_ARGS=
  57 +set _SKIP=2
  58 +
  59 +:win9xME_args_slurp
  60 +if "x%~1" == "x" goto execute
  61 +
  62 +set CMD_LINE_ARGS=%*
  63 +goto execute
  64 +
  65 +:4NT_args
  66 +@rem Get arguments from the 4NT Shell from JP Software
  67 +set CMD_LINE_ARGS=%$
  68 +
  69 +:execute
  70 +@rem Setup the command line
  71 +
  72 +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
  73 +
  74 +@rem Execute Gradle
  75 +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
  76 +
  77 +:end
  78 +@rem End local scope for the variables with windows NT shell
  79 +if "%ERRORLEVEL%"=="0" goto mainEnd
  80 +
  81 +:fail
  82 +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
  83 +rem the _cmd.exe /c_ return code!
  84 +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
  85 +exit /b 1
  86 +
  87 +:mainEnd
  88 +if "%OS%"=="Windows_NT" endlocal
  89 +
  90 +:omega
  1 +package com.lewin.qrcode;
  2 +
  3 +import android.content.Context;
  4 +import android.support.test.InstrumentationRegistry;
  5 +import android.support.test.runner.AndroidJUnit4;
  6 +
  7 +import org.junit.Test;
  8 +import org.junit.runner.RunWith;
  9 +
  10 +import static org.junit.Assert.*;
  11 +
  12 +/**
  13 + * Instrumented test, which will execute on an Android device.
  14 + *
  15 + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
  16 + */
  17 +@RunWith(AndroidJUnit4.class)
  18 +public class ExampleInstrumentedTest {
  19 + @Test
  20 + public void useAppContext() throws Exception {
  21 + // Context of the app under test.
  22 + Context appContext = InstrumentationRegistry.getTargetContext();
  23 +
  24 + assertEquals("com.lewin.qrcode", appContext.getPackageName());
  25 + }
  26 +}
  1 +<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  2 + package="com.lewin.qrcode">
  3 +
  4 + <application
  5 + android:allowBackup="true"
  6 + android:icon="@mipmap/ic_launcher"
  7 + android:label="@string/app_name"
  8 + android:roundIcon="@mipmap/ic_launcher_round"
  9 + android:supportsRtl="true"
  10 + android:theme="@style/AppTheme" />
  11 +</manifest>
  1 +package io.yimiao.bitcoin.module;
  2 +
  3 +import android.graphics.Bitmap;
  4 +import android.graphics.BitmapFactory;
  5 +
  6 +import com.facebook.react.bridge.Promise;
  7 +import com.facebook.react.bridge.ReactApplicationContext;
  8 +import com.facebook.react.bridge.ReactContextBaseJavaModule;
  9 +import com.facebook.react.bridge.ReactMethod;
  10 +import com.google.zxing.BinaryBitmap;
  11 +import com.google.zxing.ChecksumException;
  12 +import com.google.zxing.DecodeHintType;
  13 +import com.google.zxing.FormatException;
  14 +import com.google.zxing.MultiFormatReader;
  15 +import com.google.zxing.NotFoundException;
  16 +import com.google.zxing.PlanarYUVLuminanceSource;
  17 +import com.google.zxing.RGBLuminanceSource;
  18 +import com.google.zxing.ReaderException;
  19 +import com.google.zxing.Result;
  20 +import com.google.zxing.common.HybridBinarizer;
  21 +import com.google.zxing.qrcode.QRCodeReader;
  22 +
  23 +import java.util.Hashtable;
  24 +
  25 +/**
  26 + * Created by lewin on 2018/3/14.
  27 + */
  28 +
  29 +public class QRScanReader extends ReactContextBaseJavaModule {
  30 +
  31 + public QRScanReader(ReactApplicationContext reactContext) {
  32 + super(reactContext);
  33 + }
  34 +
  35 + @Override
  36 + public String getName() {
  37 + return "QRScanReader";
  38 + }
  39 +
  40 + @ReactMethod
  41 + public void readerQR(String fileUrl, Promise promise ) {
  42 + Result result = scanningImage(fileUrl);
  43 + if(result == null){
  44 + promise.reject("404","没有相关的二维码");
  45 +// result = decodeBarcodeRGB(fileUrl);
  46 +// if(result == null){
  47 +// result = decodeBarcodeYUV(fileUrl);
  48 +// if(result == null){
  49 +// promise.reject("404","没有相关的二维码");
  50 +// }else{
  51 +// promise.resolve(result.getText());
  52 +// }
  53 +// }else{
  54 +// promise.resolve(result.getText());
  55 +// }
  56 +
  57 + }else{
  58 + promise.resolve(result.getText());
  59 + }
  60 + }
  61 +
  62 + /**
  63 + * 扫描二维码图片的方法
  64 + * @param path
  65 + * @return
  66 + */
  67 + public Result scanningImage(String path) {
  68 + if (path == null || path.length() == 0) {
  69 + return null;
  70 + }
  71 + Hashtable<DecodeHintType, String> hints = new Hashtable<>();
  72 + hints.put(DecodeHintType.CHARACTER_SET, "UTF8"); //设置二维码内容的编码
  73 +
  74 + BitmapFactory.Options options = new BitmapFactory.Options();
  75 + options.inJustDecodeBounds = true; // 先获取原大小
  76 + Bitmap scanBitmap = BitmapFactory.decodeFile(path, options);
  77 + options.inJustDecodeBounds = false; // 获取新的大小
  78 + int sampleSize = (int) (options.outHeight / (float) 200);
  79 + if (sampleSize <= 0)
  80 + sampleSize = 1;
  81 + options.inSampleSize = sampleSize;
  82 + scanBitmap = BitmapFactory.decodeFile(path, options);
  83 + int width=scanBitmap.getWidth();
  84 + int height=scanBitmap.getHeight();
  85 + int[] pixels=new int[width*height];
  86 + scanBitmap.getPixels(pixels,0,width,0,0,width,height);//获取图片像素点
  87 + RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap.getWidth(),scanBitmap.getHeight(),pixels);
  88 + BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
  89 + QRCodeReader reader = new QRCodeReader();
  90 + try {
  91 + return reader.decode(bitmap1, hints);
  92 + } catch (NotFoundException e) {
  93 + e.printStackTrace();
  94 + } catch (ChecksumException e) {
  95 + e.printStackTrace();
  96 + } catch (FormatException e) {
  97 + e.printStackTrace();
  98 + }
  99 + return null;
  100 + }
  101 +
  102 + /**
  103 + * 解析二维码(使用解析RGB编码数据的方式)
  104 + *
  105 + * @param path
  106 + * @return
  107 + */
  108 + public static Result decodeBarcodeRGB(String path) {
  109 +
  110 + BitmapFactory.Options opts = new BitmapFactory.Options();
  111 + opts.inSampleSize = 1;
  112 + Bitmap barcode = BitmapFactory.decodeFile(path, opts);
  113 + Result result = decodeBarcodeRGB(barcode);
  114 + barcode.recycle();
  115 + barcode = null;
  116 + return result;
  117 + }
  118 +
  119 + /**
  120 + * 解析二维码 (使用解析RGB编码数据的方式)
  121 + *
  122 + * @param barcode
  123 + * @return
  124 + */
  125 + public static Result decodeBarcodeRGB(Bitmap barcode) {
  126 + int width = barcode.getWidth();
  127 + int height = barcode.getHeight();
  128 + int[] data = new int[width * height];
  129 + barcode.getPixels(data, 0, width, 0, 0, width, height);
  130 + RGBLuminanceSource source = new RGBLuminanceSource(width, height, data);
  131 + BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
  132 + QRCodeReader reader = new QRCodeReader();
  133 + Result result = null;
  134 + try {
  135 + result = reader.decode(bitmap1);
  136 + } catch (NotFoundException e) {
  137 + e.printStackTrace();
  138 + } catch (ChecksumException e) {
  139 + e.printStackTrace();
  140 + } catch (FormatException e) {
  141 + e.printStackTrace();
  142 + }
  143 + barcode.recycle();
  144 + barcode = null;
  145 + return result;
  146 + }
  147 +
  148 + /**
  149 + * 解析二维码(使用解析YUV编码数据的方式)
  150 + *
  151 + * @param path
  152 + * @return
  153 + */
  154 + public static Result decodeBarcodeYUV(String path) {
  155 + if (path == null || path.length() == 0) {
  156 + return null;
  157 + }
  158 + BitmapFactory.Options opts = new BitmapFactory.Options();
  159 + opts.inSampleSize = 1;
  160 + Bitmap barcode = BitmapFactory.decodeFile(path, opts);
  161 + Result result = decodeBarcodeYUV(barcode);
  162 + barcode.recycle();
  163 + barcode = null;
  164 + return result;
  165 + }
  166 +
  167 + /**
  168 + * 解析二维码(使用解析YUV编码数据的方式)
  169 + *
  170 + * @param barcode
  171 + * @return
  172 + */
  173 + public static Result decodeBarcodeYUV(Bitmap barcode) {
  174 + if (null == barcode) {
  175 + return null;
  176 + }
  177 + int width = barcode.getWidth();
  178 + int height = barcode.getHeight();
  179 + //以argb方式存放图片的像素
  180 + int[] argb = new int[width * height];
  181 + barcode.getPixels(argb, 0, width, 0, 0, width, height);
  182 + //将argb转换为yuv
  183 + byte[] yuv = new byte[width * height * 3 / 2];
  184 + encodeYUV420SP(yuv, argb, width, height);
  185 + //解析YUV编码方式的二维码
  186 + Result result = decodeBarcodeYUV(yuv, width, height);
  187 +
  188 + barcode.recycle();
  189 + barcode = null;
  190 + return result;
  191 + }
  192 +
  193 + /**
  194 + * 解析二维码(使用解析YUV编码数据的方式)
  195 + *
  196 + * @param yuv
  197 + * @param width
  198 + * @param height
  199 + * @return
  200 + */
  201 + private static Result decodeBarcodeYUV(byte[] yuv, int width, int height) {
  202 + long start = System.currentTimeMillis();
  203 + MultiFormatReader multiFormatReader = new MultiFormatReader();
  204 + multiFormatReader.setHints(null);
  205 +
  206 + Result rawResult = null;
  207 + PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(yuv, width, height, 0, 0,
  208 + width, height, false);
  209 + if (source != null) {
  210 + BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
  211 + try {
  212 + rawResult = multiFormatReader.decodeWithState(bitmap);
  213 + } catch (ReaderException re) {
  214 + re.printStackTrace();
  215 + } finally {
  216 + multiFormatReader.reset();
  217 + multiFormatReader = null;
  218 + }
  219 + }
  220 + long end = System.currentTimeMillis();
  221 + return rawResult;
  222 + }
  223 +
  224 +
  225 + /**
  226 + * RGB转YUV的公式是:
  227 + * Y=0.299R+0.587G+0.114B;
  228 + * U=-0.147R-0.289G+0.436B;
  229 + * V=0.615R-0.515G-0.1B;
  230 + *
  231 + * @param yuv
  232 + * @param argb
  233 + * @param width
  234 + * @param height
  235 + */
  236 + private static void encodeYUV420SP(byte[] yuv, int[] argb, int width, int height) {
  237 + // 帧图片的像素大小
  238 + final int frameSize = width * height;
  239 + // ---YUV数据---
  240 + int Y, U, V;
  241 + // Y的index从0开始
  242 + int yIndex = 0;
  243 + // UV的index从frameSize开始
  244 + int uvIndex = frameSize;
  245 + // ---颜色数据---
  246 + int R, G, B;
  247 + int rgbIndex = 0;
  248 + // ---循环所有像素点,RGB转YUV---
  249 + for (int j = 0; j < height; j++) {
  250 + for (int i = 0; i < width; i++) {
  251 + R = (argb[rgbIndex] & 0xff0000) >> 16;
  252 + G = (argb[rgbIndex] & 0xff00) >> 8;
  253 + B = (argb[rgbIndex] & 0xff);
  254 + //
  255 + rgbIndex++;
  256 + // well known RGB to YUV algorithm
  257 + Y = ((66 * R + 129 * G + 25 * B + 128) >> 8) + 16;
  258 + U = ((-38 * R - 74 * G + 112 * B + 128) >> 8) + 128;
  259 + V = ((112 * R - 94 * G - 18 * B + 128) >> 8) + 128;
  260 + Y = Math.max(0, Math.min(Y, 255));
  261 + U = Math.max(0, Math.min(U, 255));
  262 + V = Math.max(0, Math.min(V, 255));
  263 + // NV21 has a plane of Y and interleaved planes of VU each sampled by a factor of 2
  264 + // meaning for every 4 Y pixels there are 1 V and 1 U. Note the sampling is every other
  265 + // pixel AND every other scan line.
  266 + // ---Y---
  267 + yuv[yIndex++] = (byte) Y;
  268 + // ---UV---
  269 + if ((j % 2 == 0) && (i % 2 == 0)) {
  270 + //
  271 + yuv[uvIndex++] = (byte) V;
  272 + //
  273 + yuv[uvIndex++] = (byte) U;
  274 + }
  275 + }
  276 + }
  277 + }
  278 +}
  1 +<vector xmlns:android="http://schemas.android.com/apk/res/android"
  2 + xmlns:aapt="http://schemas.android.com/aapt"
  3 + android:width="108dp"
  4 + android:height="108dp"
  5 + android:viewportHeight="108"
  6 + android:viewportWidth="108">
  7 + <path
  8 + android:fillType="evenOdd"
  9 + android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
  10 + android:strokeColor="#00000000"
  11 + android:strokeWidth="1">
  12 + <aapt:attr name="android:fillColor">
  13 + <gradient
  14 + android:endX="78.5885"
  15 + android:endY="90.9159"
  16 + android:startX="48.7653"
  17 + android:startY="61.0927"
  18 + android:type="linear">
  19 + <item
  20 + android:color="#44000000"
  21 + android:offset="0.0" />
  22 + <item
  23 + android:color="#00000000"
  24 + android:offset="1.0" />
  25 + </gradient>
  26 + </aapt:attr>
  27 + </path>
  28 + <path
  29 + android:fillColor="#FFFFFF"
  30 + android:fillType="nonZero"
  31 + android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
  32 + android:strokeColor="#00000000"
  33 + android:strokeWidth="1" />
  34 +</vector>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<vector xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:width="108dp"
  4 + android:height="108dp"
  5 + android:viewportHeight="108"
  6 + android:viewportWidth="108">
  7 + <path
  8 + android:fillColor="#26A69A"
  9 + android:pathData="M0,0h108v108h-108z" />
  10 + <path
  11 + android:fillColor="#00000000"
  12 + android:pathData="M9,0L9,108"
  13 + android:strokeColor="#33FFFFFF"
  14 + android:strokeWidth="0.8" />
  15 + <path
  16 + android:fillColor="#00000000"
  17 + android:pathData="M19,0L19,108"
  18 + android:strokeColor="#33FFFFFF"
  19 + android:strokeWidth="0.8" />
  20 + <path
  21 + android:fillColor="#00000000"
  22 + android:pathData="M29,0L29,108"
  23 + android:strokeColor="#33FFFFFF"
  24 + android:strokeWidth="0.8" />
  25 + <path
  26 + android:fillColor="#00000000"
  27 + android:pathData="M39,0L39,108"
  28 + android:strokeColor="#33FFFFFF"
  29 + android:strokeWidth="0.8" />
  30 + <path
  31 + android:fillColor="#00000000"
  32 + android:pathData="M49,0L49,108"
  33 + android:strokeColor="#33FFFFFF"
  34 + android:strokeWidth="0.8" />
  35 + <path
  36 + android:fillColor="#00000000"
  37 + android:pathData="M59,0L59,108"
  38 + android:strokeColor="#33FFFFFF"
  39 + android:strokeWidth="0.8" />
  40 + <path
  41 + android:fillColor="#00000000"
  42 + android:pathData="M69,0L69,108"
  43 + android:strokeColor="#33FFFFFF"
  44 + android:strokeWidth="0.8" />
  45 + <path
  46 + android:fillColor="#00000000"
  47 + android:pathData="M79,0L79,108"
  48 + android:strokeColor="#33FFFFFF"
  49 + android:strokeWidth="0.8" />
  50 + <path
  51 + android:fillColor="#00000000"
  52 + android:pathData="M89,0L89,108"
  53 + android:strokeColor="#33FFFFFF"
  54 + android:strokeWidth="0.8" />
  55 + <path
  56 + android:fillColor="#00000000"
  57 + android:pathData="M99,0L99,108"
  58 + android:strokeColor="#33FFFFFF"
  59 + android:strokeWidth="0.8" />
  60 + <path
  61 + android:fillColor="#00000000"
  62 + android:pathData="M0,9L108,9"
  63 + android:strokeColor="#33FFFFFF"
  64 + android:strokeWidth="0.8" />
  65 + <path
  66 + android:fillColor="#00000000"
  67 + android:pathData="M0,19L108,19"
  68 + android:strokeColor="#33FFFFFF"
  69 + android:strokeWidth="0.8" />
  70 + <path
  71 + android:fillColor="#00000000"
  72 + android:pathData="M0,29L108,29"
  73 + android:strokeColor="#33FFFFFF"
  74 + android:strokeWidth="0.8" />
  75 + <path
  76 + android:fillColor="#00000000"
  77 + android:pathData="M0,39L108,39"
  78 + android:strokeColor="#33FFFFFF"
  79 + android:strokeWidth="0.8" />
  80 + <path
  81 + android:fillColor="#00000000"
  82 + android:pathData="M0,49L108,49"
  83 + android:strokeColor="#33FFFFFF"
  84 + android:strokeWidth="0.8" />
  85 + <path
  86 + android:fillColor="#00000000"
  87 + android:pathData="M0,59L108,59"
  88 + android:strokeColor="#33FFFFFF"
  89 + android:strokeWidth="0.8" />
  90 + <path
  91 + android:fillColor="#00000000"
  92 + android:pathData="M0,69L108,69"
  93 + android:strokeColor="#33FFFFFF"
  94 + android:strokeWidth="0.8" />
  95 + <path
  96 + android:fillColor="#00000000"
  97 + android:pathData="M0,79L108,79"
  98 + android:strokeColor="#33FFFFFF"
  99 + android:strokeWidth="0.8" />
  100 + <path
  101 + android:fillColor="#00000000"
  102 + android:pathData="M0,89L108,89"
  103 + android:strokeColor="#33FFFFFF"
  104 + android:strokeWidth="0.8" />
  105 + <path
  106 + android:fillColor="#00000000"
  107 + android:pathData="M0,99L108,99"
  108 + android:strokeColor="#33FFFFFF"
  109 + android:strokeWidth="0.8" />
  110 + <path
  111 + android:fillColor="#00000000"
  112 + android:pathData="M19,29L89,29"
  113 + android:strokeColor="#33FFFFFF"
  114 + android:strokeWidth="0.8" />
  115 + <path
  116 + android:fillColor="#00000000"
  117 + android:pathData="M19,39L89,39"
  118 + android:strokeColor="#33FFFFFF"
  119 + android:strokeWidth="0.8" />
  120 + <path
  121 + android:fillColor="#00000000"
  122 + android:pathData="M19,49L89,49"
  123 + android:strokeColor="#33FFFFFF"
  124 + android:strokeWidth="0.8" />
  125 + <path
  126 + android:fillColor="#00000000"
  127 + android:pathData="M19,59L89,59"
  128 + android:strokeColor="#33FFFFFF"
  129 + android:strokeWidth="0.8" />
  130 + <path
  131 + android:fillColor="#00000000"
  132 + android:pathData="M19,69L89,69"
  133 + android:strokeColor="#33FFFFFF"
  134 + android:strokeWidth="0.8" />
  135 + <path
  136 + android:fillColor="#00000000"
  137 + android:pathData="M19,79L89,79"
  138 + android:strokeColor="#33FFFFFF"
  139 + android:strokeWidth="0.8" />
  140 + <path
  141 + android:fillColor="#00000000"
  142 + android:pathData="M29,19L29,89"
  143 + android:strokeColor="#33FFFFFF"
  144 + android:strokeWidth="0.8" />
  145 + <path
  146 + android:fillColor="#00000000"
  147 + android:pathData="M39,19L39,89"
  148 + android:strokeColor="#33FFFFFF"
  149 + android:strokeWidth="0.8" />
  150 + <path
  151 + android:fillColor="#00000000"
  152 + android:pathData="M49,19L49,89"
  153 + android:strokeColor="#33FFFFFF"
  154 + android:strokeWidth="0.8" />
  155 + <path
  156 + android:fillColor="#00000000"
  157 + android:pathData="M59,19L59,89"
  158 + android:strokeColor="#33FFFFFF"
  159 + android:strokeWidth="0.8" />
  160 + <path
  161 + android:fillColor="#00000000"
  162 + android:pathData="M69,19L69,89"
  163 + android:strokeColor="#33FFFFFF"
  164 + android:strokeWidth="0.8" />
  165 + <path
  166 + android:fillColor="#00000000"
  167 + android:pathData="M79,19L79,89"
  168 + android:strokeColor="#33FFFFFF"
  169 + android:strokeWidth="0.8" />
  170 +</vector>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
  3 + <background android:drawable="@drawable/ic_launcher_background" />
  4 + <foreground android:drawable="@drawable/ic_launcher_foreground" />
  5 +</adaptive-icon>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
  3 + <background android:drawable="@drawable/ic_launcher_background" />
  4 + <foreground android:drawable="@drawable/ic_launcher_foreground" />
  5 +</adaptive-icon>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<resources>
  3 + <color name="colorPrimary">#3F51B5</color>
  4 + <color name="colorPrimaryDark">#303F9F</color>
  5 + <color name="colorAccent">#FF4081</color>
  6 +</resources>
  1 +<resources>
  2 + <string name="app_name">My Application</string>
  3 +</resources>
  1 +<resources>
  2 +
  3 + <!-- Base application theme. -->
  4 + <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
  5 + <!-- Customize your theme here. -->
  6 + <item name="colorPrimary">@color/colorPrimary</item>
  7 + <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
  8 + <item name="colorAccent">@color/colorAccent</item>
  9 + </style>
  10 +
  11 +</resources>
  1 +package com.lewin.qrcode;
  2 +
  3 +import org.junit.Test;
  4 +
  5 +import static org.junit.Assert.*;
  6 +
  7 +/**
  8 + * Example local unit test, which will execute on the development machine (host).
  9 + *
  10 + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
  11 + */
  12 +public class ExampleUnitTest {
  13 + @Test
  14 + public void addition_isCorrect() throws Exception {
  15 + assertEquals(4, 2 + 2);
  16 + }
  17 +}
  1 +import {
  2 + NativeModules,
  3 + } from 'react-native';
  4 + export const readerQR= (fileUrl)=>{
  5 + var QRScanReader = NativeModules.QRScanReader;
  6 +
  7 + return QRScanReader.readerQR(fileUrl);
  8 + }
  1 +// !$*UTF8*$!
  2 +{
  3 + archiveVersion = 1;
  4 + classes = {
  5 + };
  6 + objectVersion = 48;
  7 + objects = {
  8 +
  9 +/* Begin PBXBuildFile section */
  10 + 078A9483208738FB00EC805D /* QrCode.h in Headers */ = {isa = PBXBuildFile; fileRef = 078A9481208738FB00EC805D /* QrCode.h */; settings = {ATTRIBUTES = (Public, ); }; };
  11 + 078A94AB20873A0700EC805D /* QRScanReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 078A94A920873A0700EC805D /* QRScanReader.h */; settings = {ATTRIBUTES = (Public, ); }; };
  12 + 078A94AC20873A0700EC805D /* QRScanReader.m in Sources */ = {isa = PBXBuildFile; fileRef = 078A94AA20873A0700EC805D /* QRScanReader.m */; };
  13 +/* End PBXBuildFile section */
  14 +
  15 +/* Begin PBXFileReference section */
  16 + 078A947E208738FB00EC805D /* QrCode.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = QrCode.framework; sourceTree = BUILT_PRODUCTS_DIR; };
  17 + 078A9481208738FB00EC805D /* QrCode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QrCode.h; sourceTree = "<group>"; };
  18 + 078A9482208738FB00EC805D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
  19 + 078A94A920873A0700EC805D /* QRScanReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QRScanReader.h; sourceTree = "<group>"; };
  20 + 078A94AA20873A0700EC805D /* QRScanReader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QRScanReader.m; sourceTree = "<group>"; };
  21 +/* End PBXFileReference section */
  22 +
  23 +/* Begin PBXFrameworksBuildPhase section */
  24 + 078A947A208738FB00EC805D /* Frameworks */ = {
  25 + isa = PBXFrameworksBuildPhase;
  26 + buildActionMask = 2147483647;
  27 + files = (
  28 + );
  29 + runOnlyForDeploymentPostprocessing = 0;
  30 + };
  31 +/* End PBXFrameworksBuildPhase section */
  32 +
  33 +/* Begin PBXGroup section */
  34 + 078A9474208738FB00EC805D = {
  35 + isa = PBXGroup;
  36 + children = (
  37 + 078A9480208738FB00EC805D /* QrCode */,
  38 + 078A947F208738FB00EC805D /* Products */,
  39 + );
  40 + sourceTree = "<group>";
  41 + };
  42 + 078A947F208738FB00EC805D /* Products */ = {
  43 + isa = PBXGroup;
  44 + children = (
  45 + 078A947E208738FB00EC805D /* QrCode.framework */,
  46 + );
  47 + name = Products;
  48 + sourceTree = "<group>";
  49 + };
  50 + 078A9480208738FB00EC805D /* QrCode */ = {
  51 + isa = PBXGroup;
  52 + children = (
  53 + 078A94A920873A0700EC805D /* QRScanReader.h */,
  54 + 078A94AA20873A0700EC805D /* QRScanReader.m */,
  55 + 078A9481208738FB00EC805D /* QrCode.h */,
  56 + 078A9482208738FB00EC805D /* Info.plist */,
  57 + );
  58 + path = QrCode;
  59 + sourceTree = "<group>";
  60 + };
  61 +/* End PBXGroup section */
  62 +
  63 +/* Begin PBXHeadersBuildPhase section */
  64 + 078A947B208738FB00EC805D /* Headers */ = {
  65 + isa = PBXHeadersBuildPhase;
  66 + buildActionMask = 2147483647;
  67 + files = (
  68 + 078A9483208738FB00EC805D /* QrCode.h in Headers */,
  69 + 078A94AB20873A0700EC805D /* QRScanReader.h in Headers */,
  70 + );
  71 + runOnlyForDeploymentPostprocessing = 0;
  72 + };
  73 +/* End PBXHeadersBuildPhase section */
  74 +
  75 +/* Begin PBXNativeTarget section */
  76 + 078A947D208738FB00EC805D /* QrCode */ = {
  77 + isa = PBXNativeTarget;
  78 + buildConfigurationList = 078A9486208738FB00EC805D /* Build configuration list for PBXNativeTarget "QrCode" */;
  79 + buildPhases = (
  80 + 078A9479208738FB00EC805D /* Sources */,
  81 + 078A947A208738FB00EC805D /* Frameworks */,
  82 + 078A947B208738FB00EC805D /* Headers */,
  83 + 078A947C208738FB00EC805D /* Resources */,
  84 + );
  85 + buildRules = (
  86 + );
  87 + dependencies = (
  88 + );
  89 + name = QrCode;
  90 + productName = QrCode;
  91 + productReference = 078A947E208738FB00EC805D /* QrCode.framework */;
  92 + productType = "com.apple.product-type.framework";
  93 + };
  94 +/* End PBXNativeTarget section */
  95 +
  96 +/* Begin PBXProject section */
  97 + 078A9475208738FB00EC805D /* Project object */ = {
  98 + isa = PBXProject;
  99 + attributes = {
  100 + LastUpgradeCheck = 0920;
  101 + ORGANIZATIONNAME = lewin;
  102 + TargetAttributes = {
  103 + 078A947D208738FB00EC805D = {
  104 + CreatedOnToolsVersion = 9.2;
  105 + ProvisioningStyle = Automatic;
  106 + };
  107 + };
  108 + };
  109 + buildConfigurationList = 078A9478208738FB00EC805D /* Build configuration list for PBXProject "QrCode" */;
  110 + compatibilityVersion = "Xcode 8.0";
  111 + developmentRegion = en;
  112 + hasScannedForEncodings = 0;
  113 + knownRegions = (
  114 + en,
  115 + );
  116 + mainGroup = 078A9474208738FB00EC805D;
  117 + productRefGroup = 078A947F208738FB00EC805D /* Products */;
  118 + projectDirPath = "";
  119 + projectRoot = "";
  120 + targets = (
  121 + 078A947D208738FB00EC805D /* QrCode */,
  122 + );
  123 + };
  124 +/* End PBXProject section */
  125 +
  126 +/* Begin PBXResourcesBuildPhase section */
  127 + 078A947C208738FB00EC805D /* Resources */ = {
  128 + isa = PBXResourcesBuildPhase;
  129 + buildActionMask = 2147483647;
  130 + files = (
  131 + );
  132 + runOnlyForDeploymentPostprocessing = 0;
  133 + };
  134 +/* End PBXResourcesBuildPhase section */
  135 +
  136 +/* Begin PBXSourcesBuildPhase section */
  137 + 078A9479208738FB00EC805D /* Sources */ = {
  138 + isa = PBXSourcesBuildPhase;
  139 + buildActionMask = 2147483647;
  140 + files = (
  141 + 078A94AC20873A0700EC805D /* QRScanReader.m in Sources */,
  142 + );
  143 + runOnlyForDeploymentPostprocessing = 0;
  144 + };
  145 +/* End PBXSourcesBuildPhase section */
  146 +
  147 +/* Begin XCBuildConfiguration section */
  148 + 078A9484208738FB00EC805D /* Debug */ = {
  149 + isa = XCBuildConfiguration;
  150 + buildSettings = {
  151 + ALWAYS_SEARCH_USER_PATHS = NO;
  152 + CLANG_ANALYZER_NONNULL = YES;
  153 + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
  154 + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
  155 + CLANG_CXX_LIBRARY = "libc++";
  156 + CLANG_ENABLE_MODULES = YES;
  157 + CLANG_ENABLE_OBJC_ARC = YES;
  158 + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
  159 + CLANG_WARN_BOOL_CONVERSION = YES;
  160 + CLANG_WARN_COMMA = YES;
  161 + CLANG_WARN_CONSTANT_CONVERSION = YES;
  162 + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
  163 + CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
  164 + CLANG_WARN_EMPTY_BODY = YES;
  165 + CLANG_WARN_ENUM_CONVERSION = YES;
  166 + CLANG_WARN_INFINITE_RECURSION = YES;
  167 + CLANG_WARN_INT_CONVERSION = YES;
  168 + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
  169 + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
  170 + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
  171 + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
  172 + CLANG_WARN_STRICT_PROTOTYPES = YES;
  173 + CLANG_WARN_SUSPICIOUS_MOVE = YES;
  174 + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
  175 + CLANG_WARN_UNREACHABLE_CODE = YES;
  176 + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
  177 + CODE_SIGN_IDENTITY = "iPhone Developer";
  178 + COPY_PHASE_STRIP = NO;
  179 + CURRENT_PROJECT_VERSION = 1;
  180 + DEBUG_INFORMATION_FORMAT = dwarf;
  181 + ENABLE_STRICT_OBJC_MSGSEND = YES;
  182 + ENABLE_TESTABILITY = YES;
  183 + GCC_C_LANGUAGE_STANDARD = gnu11;
  184 + GCC_DYNAMIC_NO_PIC = NO;
  185 + GCC_NO_COMMON_BLOCKS = YES;
  186 + GCC_OPTIMIZATION_LEVEL = 0;
  187 + GCC_PREPROCESSOR_DEFINITIONS = (
  188 + "DEBUG=1",
  189 + "$(inherited)",
  190 + );
  191 + GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
  192 + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
  193 + GCC_WARN_UNDECLARED_SELECTOR = YES;
  194 + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
  195 + GCC_WARN_UNUSED_FUNCTION = YES;
  196 + GCC_WARN_UNUSED_VARIABLE = YES;
  197 + IPHONEOS_DEPLOYMENT_TARGET = 11.2;
  198 + MTL_ENABLE_DEBUG_INFO = YES;
  199 + ONLY_ACTIVE_ARCH = YES;
  200 + SDKROOT = iphoneos;
  201 + VERSIONING_SYSTEM = "apple-generic";
  202 + VERSION_INFO_PREFIX = "";
  203 + };
  204 + name = Debug;
  205 + };
  206 + 078A9485208738FB00EC805D /* Release */ = {
  207 + isa = XCBuildConfiguration;
  208 + buildSettings = {
  209 + ALWAYS_SEARCH_USER_PATHS = NO;
  210 + CLANG_ANALYZER_NONNULL = YES;
  211 + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
  212 + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
  213 + CLANG_CXX_LIBRARY = "libc++";
  214 + CLANG_ENABLE_MODULES = YES;
  215 + CLANG_ENABLE_OBJC_ARC = YES;
  216 + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
  217 + CLANG_WARN_BOOL_CONVERSION = YES;
  218 + CLANG_WARN_COMMA = YES;
  219 + CLANG_WARN_CONSTANT_CONVERSION = YES;
  220 + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
  221 + CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
  222 + CLANG_WARN_EMPTY_BODY = YES;
  223 + CLANG_WARN_ENUM_CONVERSION = YES;
  224 + CLANG_WARN_INFINITE_RECURSION = YES;
  225 + CLANG_WARN_INT_CONVERSION = YES;
  226 + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
  227 + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
  228 + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
  229 + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
  230 + CLANG_WARN_STRICT_PROTOTYPES = YES;
  231 + CLANG_WARN_SUSPICIOUS_MOVE = YES;
  232 + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
  233 + CLANG_WARN_UNREACHABLE_CODE = YES;
  234 + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
  235 + CODE_SIGN_IDENTITY = "iPhone Developer";
  236 + COPY_PHASE_STRIP = NO;
  237 + CURRENT_PROJECT_VERSION = 1;
  238 + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
  239 + ENABLE_NS_ASSERTIONS = NO;
  240 + ENABLE_STRICT_OBJC_MSGSEND = YES;
  241 + GCC_C_LANGUAGE_STANDARD = gnu11;
  242 + GCC_NO_COMMON_BLOCKS = YES;
  243 + GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
  244 + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
  245 + GCC_WARN_UNDECLARED_SELECTOR = YES;
  246 + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
  247 + GCC_WARN_UNUSED_FUNCTION = YES;
  248 + GCC_WARN_UNUSED_VARIABLE = YES;
  249 + IPHONEOS_DEPLOYMENT_TARGET = 11.2;
  250 + MTL_ENABLE_DEBUG_INFO = NO;
  251 + SDKROOT = iphoneos;
  252 + VALIDATE_PRODUCT = YES;
  253 + VERSIONING_SYSTEM = "apple-generic";
  254 + VERSION_INFO_PREFIX = "";
  255 + };
  256 + name = Release;
  257 + };
  258 + 078A9487208738FB00EC805D /* Debug */ = {
  259 + isa = XCBuildConfiguration;
  260 + buildSettings = {
  261 + CODE_SIGN_IDENTITY = "";
  262 + CODE_SIGN_STYLE = Automatic;
  263 + DEFINES_MODULE = YES;
  264 + DYLIB_COMPATIBILITY_VERSION = 1;
  265 + DYLIB_CURRENT_VERSION = 1;
  266 + DYLIB_INSTALL_NAME_BASE = "@rpath";
  267 + INFOPLIST_FILE = QrCode/Info.plist;
  268 + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
  269 + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
  270 + PRODUCT_BUNDLE_IDENTIFIER = com.lewin.QrCode;
  271 + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
  272 + SKIP_INSTALL = YES;
  273 + TARGETED_DEVICE_FAMILY = "1,2";
  274 + };
  275 + name = Debug;
  276 + };
  277 + 078A9488208738FB00EC805D /* Release */ = {
  278 + isa = XCBuildConfiguration;
  279 + buildSettings = {
  280 + CODE_SIGN_IDENTITY = "";
  281 + CODE_SIGN_STYLE = Automatic;
  282 + DEFINES_MODULE = YES;
  283 + DYLIB_COMPATIBILITY_VERSION = 1;
  284 + DYLIB_CURRENT_VERSION = 1;
  285 + DYLIB_INSTALL_NAME_BASE = "@rpath";
  286 + INFOPLIST_FILE = QrCode/Info.plist;
  287 + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
  288 + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
  289 + PRODUCT_BUNDLE_IDENTIFIER = com.lewin.QrCode;
  290 + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
  291 + SKIP_INSTALL = YES;
  292 + TARGETED_DEVICE_FAMILY = "1,2";
  293 + };
  294 + name = Release;
  295 + };
  296 +/* End XCBuildConfiguration section */
  297 +
  298 +/* Begin XCConfigurationList section */
  299 + 078A9478208738FB00EC805D /* Build configuration list for PBXProject "QrCode" */ = {
  300 + isa = XCConfigurationList;
  301 + buildConfigurations = (
  302 + 078A9484208738FB00EC805D /* Debug */,
  303 + 078A9485208738FB00EC805D /* Release */,
  304 + );
  305 + defaultConfigurationIsVisible = 0;
  306 + defaultConfigurationName = Release;
  307 + };
  308 + 078A9486208738FB00EC805D /* Build configuration list for PBXNativeTarget "QrCode" */ = {
  309 + isa = XCConfigurationList;
  310 + buildConfigurations = (
  311 + 078A9487208738FB00EC805D /* Debug */,
  312 + 078A9488208738FB00EC805D /* Release */,
  313 + );
  314 + defaultConfigurationIsVisible = 0;
  315 + defaultConfigurationName = Release;
  316 + };
  317 +/* End XCConfigurationList section */
  318 + };
  319 + rootObject = 078A9475208738FB00EC805D /* Project object */;
  320 +}
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  3 +<plist version="1.0">
  4 +<dict>
  5 + <key>CFBundleDevelopmentRegion</key>
  6 + <string>$(DEVELOPMENT_LANGUAGE)</string>
  7 + <key>CFBundleExecutable</key>
  8 + <string>$(EXECUTABLE_NAME)</string>
  9 + <key>CFBundleIdentifier</key>
  10 + <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
  11 + <key>CFBundleInfoDictionaryVersion</key>
  12 + <string>6.0</string>
  13 + <key>CFBundleName</key>
  14 + <string>$(PRODUCT_NAME)</string>
  15 + <key>CFBundlePackageType</key>
  16 + <string>FMWK</string>
  17 + <key>CFBundleShortVersionString</key>
  18 + <string>1.0</string>
  19 + <key>CFBundleVersion</key>
  20 + <string>$(CURRENT_PROJECT_VERSION)</string>
  21 + <key>NSPrincipalClass</key>
  22 + <string></string>
  23 +</dict>
  24 +</plist>
  1 +//
  2 +// QRScanReader.h
  3 +// Bitcoin
  4 +//
  5 +// Created by lewin on 2018/3/14.
  6 +// Copyright © 2018年 Facebook. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +#import <React/RCTBridgeModule.h>
  11 +
  12 +@interface QRScanReader : NSObject<RCTBridgeModule>
  13 +
  14 +@end
  1 +//
  2 +// QRScanReader.m
  3 +// Bitcoin
  4 +//
  5 +// Created by lewin on 2018/3/14.
  6 +// Copyright © 2018年 Facebook. All rights reserved.
  7 +//
  8 +
  9 +#import "QRScanReader.h"
  10 +#import <AVFoundation/AVFoundation.h>
  11 +#import <CoreImage/CoreImage.h>
  12 +
  13 +@implementation QRScanReader
  14 +RCT_EXPORT_MODULE();
  15 +
  16 +RCT_EXPORT_METHOD(readerQR:(NSString *)fileUrl success:(RCTPromiseResolveBlock)success failure:(RCTResponseErrorBlock)failure){
  17 + dispatch_sync(dispatch_get_main_queue(), ^{
  18 + NSString *result = [self readerQR:fileUrl];
  19 + if(result){
  20 + success(result);
  21 + }else{
  22 + NSString *domain = @"yitang.xiao";
  23 + NSString *desc = NSLocalizedString(@"没有相关二维码", @"");
  24 + NSDictionary *userInfo = @{ NSLocalizedDescriptionKey : desc };
  25 + NSError *error = [NSError errorWithDomain:domain
  26 + code:404
  27 + userInfo:userInfo];
  28 + failure(error);
  29 + }
  30 + });
  31 +
  32 +
  33 +
  34 +}
  35 +
  36 +-(NSString*)readerQR:(NSString*)fileUrl{
  37 + fileUrl = [fileUrl stringByReplacingOccurrencesOfString:@"file://" withString:@""];
  38 +
  39 + CIContext *context = [CIContext contextWithOptions:nil];
  40 +
  41 + // CIDetector(CIDetector可用于人脸识别)进行图片解析,声明一个CIDetector,并设定识别类型 CIDetectorTypeQRCode
  42 + CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:context options:@{CIDetectorAccuracy:CIDetectorAccuracyHigh}];
  43 + NSData *fileData = [[NSData alloc] initWithContentsOfFile:fileUrl];
  44 + CIImage *ciImage = [CIImage imageWithData:fileData];
  45 + NSArray *features = [detector featuresInImage:ciImage];
  46 + if(!features || features.count==0){
  47 + return nil;
  48 + }
  49 + //3. 获取扫描结果
  50 + CIQRCodeFeature *feature = [features objectAtIndex:0];
  51 + NSString *scannedResult = feature.messageString;
  52 + return scannedResult;
  53 +}
  54 +
  55 +@end
  1 +//
  2 +// QrCode.h
  3 +// QrCode
  4 +//
  5 +// Created by lewin on 2018/4/18.
  6 +// Copyright © 2018年 lewin. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +//! Project version number for QrCode.
  12 +FOUNDATION_EXPORT double QrCodeVersionNumber;
  13 +
  14 +//! Project version string for QrCode.
  15 +FOUNDATION_EXPORT const unsigned char QrCodeVersionString[];
  16 +
  17 +// In this header, you should import all the public headers of your framework using statements like #import <QrCode/PublicHeader.h>
  18 +
  19 +
  1 +{
  2 + "name": "react-native-lewin-qrcode",
  3 + "version": "1.0.0",
  4 + "lockfileVersion": 1
  5 +}
  1 +{
  2 + "name": "react-native-lewin-qrcode",
  3 + "version": "1.0.0",
  4 + "description": "二维码识别",
  5 + "main": "index.js",
  6 + "scripts": {
  7 + "test": "echo \"Error: no test specified\" && exit 1"
  8 + },
  9 + "repository": {
  10 + "type": "git",
  11 + "url": "git+https://github.com/LewinJun/react-native-lewin-qrcode.git"
  12 + },
  13 + "keywords": [
  14 + "qrcode"
  15 + ],
  16 + "author": "lewin",
  17 + "license": "ISC",
  18 + "bugs": {
  19 + "url": "https://github.com/LewinJun/react-native-lewin-qrcode/issues"
  20 + },
  21 + "homepage": "https://github.com/LewinJun/react-native-lewin-qrcode#readme",
  22 + "peerDependencies": {
  23 + "react-native": "latest"
  24 + }
  25 +}