从命令提示符转到应用程序的根文件夹。
您可以使用我们的插件形式NPM(推荐),或者您可以从中下载这里and use from local path.
TNS插件添加CMBSDK-NativeScript#或本地路径
探索插件使用的最佳方式是检查我们的演示应用程序。您可以从中下载我们的演示应用程序这里。
Once you download navigate to demo app root folder and run demo application:
CD CMBSDK_NAISIPT / DEMO TNS运行Android#或iOS
简而言之,在您的项目中使用我们的插件是以下步骤:
import { CMBReader, CMBReaderConstants } from 'cmbsdk-nativescript';
打开主页 - 查看-Model.ts从演示应用程序查看此代码。我们的演示应用程序中的所有代码都是简短的描述。
this.cmb。startscanning()
重要的
使用MX设备使用CMBSDK NativeScript插件是免费的,但如果要利用相机设备(使用智能手机相机扫描),则需要获取许可证CMBDN。
he Reader still works without a license, but results are randomly masked with * chars.
它可以免费注册,您可以获得30天的试用许可证密钥。
一旦获得了键,有两种方法可以在您的应用程序中使用。
this.cmbReader.registerSDK("SKD_KEY");
为了获得扫描仪,首先要做的是要打电话给loadscanner()method. It expects a CMBReaderConstants.DEVICE_TYPE param. This method does not connect to the Reader Device. We need to call连接()in the callback to actually connect to the Reader Device
this..cmb.loadscanner(cmbreaderconstants.device_type.mxReader)。然后(结果=> {this.cmb.connect().then(结果=> {...}).catch(err => {console.log(err);});});
/* @return (promise) { status : boolean, if connection succeeded true if not false err : string , if status false err will not be null } */
Connect()方法的结果作为承诺返回,它将包含连接尝试的结果:
this..cmb.connect().then(结果=> {...}).catch(err => {console.log(错误);});
有一个事件侦听器,用于readerDevice的连接状态,即cmbreaderconstants.Events.ConnectionStateChanged.事件下面更详细地解释。
/ * @return(承诺){status:boolean,如果disconnect成功了,如果不是false err:string,如果status false err为null} * /
就像有连接(),有一个断开()method that does the opposite of连接():
this.cmb.disconnect();
同样到连接(),断开()也触发了这一点cmbreaderconstants.Events.ConnectionStateChanged.事件。
/ * @return承诺(bool)扫描仪活动的值(如果命令成功,则为true,否则否则:如果读取器没有初始化)* /
要启动/停止扫描过程,我们使用这些方法。它们返回一个承诺,如果命令成功(扫描已启动或停止)或否则拒绝
After starting the scanner and scanning a barcode, the scan result triggers thecmbreaderconstants.Events.ReadResultreCeived事件。
一旦与读者连接,我们就可以通过调用来启用符号SetyymbologyEnabled()。It expects three params: a CMBReaderConstants.SYMBOLOGY which is the symbology to be enabled or disabled and a boolean for ON/OFF.
this.cmb.setsymbologyEnenabled(cmbreaderconstants.symbology.datamatrix,true).then(函数(结果){if(结果== true)console.log(启用“datamatrix”); else console.log(“datamatrix未启用”);}).catch(函数(err){console.log(错误);});
要检查我们是否启用了符号,我们使用IssymbologyEnabled()。它需要参数cmbreaderconstants.symbology。
cmb.issymbologyenabled(cmbreaderconstants.symbology.qr).then(函数(结果){if(结果== true)console.log(启用“dataMatrix”); else console.log(“datamatrix未启用”);})。catch(函数(err){console.log(错误);});
/* @return (promise) { status : boolean, true if successfully executed command err : string , if status false err will not be null } */
If we want to enable the flash we can use石碑()。它期望一个争论布尔和返回承诺。
/ * @return(承诺){status:boolean,true如果灯亮,则为false否则错误:字符串,在错误(例如读者未初始化)} * /
我们可以使用Islialson()检查灯光状态,返回承诺。
/** @return A promise that resolves with the CMBReaderConstants.CONNECTION_STATE value of the current reader device */
如果您需要获取当前的连接状态,getConnectionState()可以使用
this.cmb.getConnectionState()。然后(函数(connectionstate){if(connectionstate == cmbreaderconstants.connection_state.connected){// reader已连接}});
只有在使用相机内置的设备以进行扫描时,应仅使用此操作(cmbreaderconstants.device_type.camera)。
This function expects one integer argument that is a result of the OR-ed result of all the preview options that we want enabled.
this.cmb。setPreviewOptions.(CMBReaderConstants.CAMERA_PREVIEW_OPTION.NoZoomBtn | CMBReaderConstants.CAMERA_PREVIEW_OPTION.NoIllumBtn);
笔记:PreviewOptions should be set BEFORE we callloadscanner()为了生效。
只有在使用相机内置的设备以进行扫描时,应仅使用此操作(cmbreaderconstants.device_type.camera)。
this.cmb.setPreviewContainerPositionAndsize([0,0,100,50]);//将预览设置为0,0和100%宽度50%高度
只有在使用相机内置的设备以进行扫描时,应仅使用此操作(cmbreaderconstants.device_type.camera)。
Sets the camera preview to start in full screen instead of partial view.
this.cmb。setPreviewContainerFullScreen();
用于启用/禁用图像结果类型。期待一个布尔的论点。
this.cmb.enableImage(真实);
用于启用/禁用SVG结果类型。期待一个布尔的论点。
this.cmb.EnableImageGraphics(真实);
Enable or disable parsing for scanned barcodes. Expects one argument of type CMBReaderConstants.RESULT_PARSER.
this.cmb。setparser.(CMBReaderConstants.RESULT_PARSER.GS1);
设置读取结果类型的编码。期望CMBreaderConstants.readString_Encoding类型的一个参数。
this.cmb。setreadstringencoding.(CMBReaderConstants.READSTRING_ENCODING.UTF_8);
/ * @return(承诺){value:int err:string,在错误(例如reader未初始化)} * /
Method to show the battery level of the connected device. Doesn't take any arguments.
所有方法都可以用向读取器设备发送DMCC字符串替换。为此,我们可以使用我们的API方法SendCommand.。It can be used to control the Reader completely with command strings. It takes two string arguments, first of which is the DMCC itself, and the second one is to identify it in the response event.
this.cmb。SendCommand.("GET DEVICE.TYPE") .then(function (result) { console.log(result); }) .catch(function (result) { console.log(result); });
仅适用于iOS。
用于创建用于MDM报告的身份验证凭据。它需要四个字符串参数:用户名,密码,clientId和clientsecret。
Should be called before setMDMReportingEnabled.
可以找到更多关于MDM报告这里
this.cmb。createmdmauthcredentials.("username", "password", "clientID", "clientSecret");
仅适用于iOS。
拥有和运营许多可康生移动终端的公司可能希望远程收集有关电池电量,电池运行状况,安装固件等的最新信息。
使用CMBSDK框架的IOS应用程序可以将附加的移动终端的状态信息报告给MDM实例。这可以通过接受一个布尔参数的setMdmreportingEnabled方法启用。
可以找到更多关于MDM报告这里
this.cmb.setmdmreportingEnabled(true);
/ * @return(承诺){范围:JSON对象具有这些属性“较低”:MIN相机曝光值“Upper”:Max Camera曝光值“步骤”:相机曝光步骤值ERR:字符串,在错误情况下(例如读者未初始化)} * /
cmb.getCameraExposureCompensationRange().then(function (range) { console.log(range); }) .catch(function (err) { console.log(err); });
笔记:相机需要在CMBSDK内启动,至少一次以获得相机曝光补偿范围,否则会返回空的JSON。
设置相机曝光补偿值。发送将被设置为曝光补偿的浮点值。
CMB.SetCameraExpoSurecolation(5).catch(函数(err){console.log(错误);});
笔记:在成功连接到读取器设备后,需要调用这一点。如果发送的值大于相机曝光最大值,则将设置最大值,如果发送的值低于相机曝光min值,则将设置最小值。
CMBSDK插件发出可在应用程序中使用的事件。
首先,创建活动发射器:
导入NativeModules.nativePentemitter;const scannerlistener =新的nativeEventEmitter(CMB);
然后为您要处理的每个事件添加侦听器:
这个。消息:“设备变得不可用”,OKBUTTONTEXT:“OK”});}};
以下是CMBSDK插件可以发出的所有事件:
cmbreaderconstants.Event.ReadResultReceivedCMBReaderConstants.EVENT.AvailabilityChanged CMBReaderConstants.EVENT.ConnectionStateChanged CMBReaderConstants.EVENT.ScanningStateChanged