条形码扫描库在 iOS 上不起作用,但在 Android 上起作用
the barcode scan library doesn't work on iOS but it does on Android
我尝试使用此库在 iOS 上使用条码扫描器:https://github.com/codenameone/cn1-codescan 它在 Android 上运行良好,但是当我的应用程序在 iOS,我的应用程序只是关闭而没有显示任何错误消息。
我必须扫描 Code 128 条形码。
也许我必须编辑 属性 尤其是 IOS ?
这是我的代码:
public class ScanCode extends Form {
final Container cnt = this;
public ScanCode(Form parent){
this.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
Display.getInstance().setProperty("android.scanTypes", "CODE_128");
CodeScanner.getInstance().scanBarCode(new ScanResult() {
public void scanCompleted(String contents, String formatName, byte[] rawBytes) {
String word;
word= contents.substring(0,12);
List<Patient> myList= new ArrayList<>();
myList= RestManager.getList(contents.substring(0,12));
if(myList.size()==0){
new ManualInfo(parent,contents).show();
}
else{
Date date = new Date();
Intervention intervention = new Intervention();
intervention.setList(myList.get(0));
intervention.setDateAction(date);
intervention.setDateCreate(date);
intervention.setDateUpdate(date);
intervention.setEncodingType(Intervention.BARCODE_TYPE);
Update ajoutintervention = new Update();
ajoutintervention.setId((long) 0);
ajoutintervention.setDatas(intervention.toJson());
ajoutintervention.setDateCreate(date);
ajoutintervention.setDateUpdate(date);
ajoutintervention.setTreatment(String.valueOf(Constants.INSERT));
ajoutintervention.setDone(String.valueOf(false));
ajoutintervention.setClassName(intervention.getName());
ajoutintervention.setParam(myList.get(0).getWord());
DatabaseHelper.saveDataClass(ajoutintervention);
}
}
public void scanCanceled() {
cnt.addComponent(new Label("cancelled"));
}
public void scanError(int errorCode, String message) {
cnt.addComponent(new Label("err " + message));
}
});
}
编辑:
这是构建提示:
codename1.arg.ios.add_libs=ExternalAccessory.framework;CoreBluetooth.framework;libc++.dylib;SystemConfiguration.framework;,libc++.dylib,CoreText.framework,MessageUI.framework,CoreVideo.framework,CoreMedia.framework
codename1.arg.ios.background_modes=,bluetooth-central,bluetooth-peripheral
codename1.arg.ios.debug.archs=arm64
codename1.arg.ios.includePush=true
codename1.arg.ios.newStorageLocation=true
codename1.arg.ios.plistInject=<key>NSBluetoothPeripheralUsageDescription</key><string>This app uses a BLE cardreader</string><key>UISupportedExternalAccessoryProtocols</key><array><string>bt.reader.library</string></array> <key>NSAppTransportSecurity</key> <dict><key>NSAllowsArbitraryLoads</key><true/></dict>
codename1.arg.ios.pods.platform=8.0,7.0
codename1.arg.ios.pods.sources=https\://github.com/CocoaPods/Specs.git
codename1.arg.ios.xcode_version=10.1
codename1.arg.java.version=8
我在 12.1 iOS 版本上工作,设备是 iPad Air。
确保您的 cn1lib 是最新的,并且您 运行 在模拟器上也是如此。您需要定义 ios.NSCameraUsageDescription
构建提示(如果直接编辑文件,则为 codename1.arg.ios.NSCameraUsageDescription
)。这是 iOS 当前版本所要求的。当您 运行 模拟器中的代码时,库会隐式添加此内容。
我尝试使用此库在 iOS 上使用条码扫描器:https://github.com/codenameone/cn1-codescan 它在 Android 上运行良好,但是当我的应用程序在 iOS,我的应用程序只是关闭而没有显示任何错误消息。 我必须扫描 Code 128 条形码。 也许我必须编辑 属性 尤其是 IOS ?
这是我的代码:
public class ScanCode extends Form {
final Container cnt = this;
public ScanCode(Form parent){
this.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
Display.getInstance().setProperty("android.scanTypes", "CODE_128");
CodeScanner.getInstance().scanBarCode(new ScanResult() {
public void scanCompleted(String contents, String formatName, byte[] rawBytes) {
String word;
word= contents.substring(0,12);
List<Patient> myList= new ArrayList<>();
myList= RestManager.getList(contents.substring(0,12));
if(myList.size()==0){
new ManualInfo(parent,contents).show();
}
else{
Date date = new Date();
Intervention intervention = new Intervention();
intervention.setList(myList.get(0));
intervention.setDateAction(date);
intervention.setDateCreate(date);
intervention.setDateUpdate(date);
intervention.setEncodingType(Intervention.BARCODE_TYPE);
Update ajoutintervention = new Update();
ajoutintervention.setId((long) 0);
ajoutintervention.setDatas(intervention.toJson());
ajoutintervention.setDateCreate(date);
ajoutintervention.setDateUpdate(date);
ajoutintervention.setTreatment(String.valueOf(Constants.INSERT));
ajoutintervention.setDone(String.valueOf(false));
ajoutintervention.setClassName(intervention.getName());
ajoutintervention.setParam(myList.get(0).getWord());
DatabaseHelper.saveDataClass(ajoutintervention);
}
}
public void scanCanceled() {
cnt.addComponent(new Label("cancelled"));
}
public void scanError(int errorCode, String message) {
cnt.addComponent(new Label("err " + message));
}
});
}
编辑: 这是构建提示:
codename1.arg.ios.add_libs=ExternalAccessory.framework;CoreBluetooth.framework;libc++.dylib;SystemConfiguration.framework;,libc++.dylib,CoreText.framework,MessageUI.framework,CoreVideo.framework,CoreMedia.framework
codename1.arg.ios.background_modes=,bluetooth-central,bluetooth-peripheral
codename1.arg.ios.debug.archs=arm64
codename1.arg.ios.includePush=true
codename1.arg.ios.newStorageLocation=true
codename1.arg.ios.plistInject=<key>NSBluetoothPeripheralUsageDescription</key><string>This app uses a BLE cardreader</string><key>UISupportedExternalAccessoryProtocols</key><array><string>bt.reader.library</string></array> <key>NSAppTransportSecurity</key> <dict><key>NSAllowsArbitraryLoads</key><true/></dict>
codename1.arg.ios.pods.platform=8.0,7.0
codename1.arg.ios.pods.sources=https\://github.com/CocoaPods/Specs.git
codename1.arg.ios.xcode_version=10.1
codename1.arg.java.version=8
我在 12.1 iOS 版本上工作,设备是 iPad Air。
确保您的 cn1lib 是最新的,并且您 运行 在模拟器上也是如此。您需要定义 ios.NSCameraUsageDescription
构建提示(如果直接编辑文件,则为 codename1.arg.ios.NSCameraUsageDescription
)。这是 iOS 当前版本所要求的。当您 运行 模拟器中的代码时,库会隐式添加此内容。