Objective c Socket Mobile SocketScan SDK和Swift

Objective c Socket Mobile SocketScan SDK和Swift,objective-c,swift,barcode-scanner,socketscan,socketmobile,Objective C,Swift,Barcode Scanner,Socketscan,Socketmobile,我正在尝试将SocketScan SDK与用Swift编写的应用程序一起使用。使用桥接头,Objective-C代码很容易导入。但是,在运行应用程序时,它在OnDevicarrival阶段崩溃,Xcode引用了“无法识别的选择器”。也就是说,ScanApi打开并运行,当设备到达时,应用程序崩溃,出现以下错误: -[SocketConnect.ViewController onDeviceArrival:设备:]:发送到实例0x15550e670的无法识别的选择器 *由于未捕获的异常“NSInva

我正在尝试将SocketScan SDK与用Swift编写的应用程序一起使用。使用桥接头,Objective-C代码很容易导入。但是,在运行应用程序时,它在OnDevicarrival阶段崩溃,Xcode引用了“无法识别的选择器”。也就是说,ScanApi打开并运行,当设备到达时,应用程序崩溃,出现以下错误:

-[SocketConnect.ViewController onDeviceArrival:设备:]:发送到实例0x15550e670的无法识别的选择器 *由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[SocketConnect.ViewController onDeviceArrival:Device::]:无法识别的选择器发送到实例0x15550e670' *第一次抛出调用堆栈: (0x185a9259c 0x1961e40e4 0x185a99664 0x185a96230 0x18599ab6c 0x1000b2798 0x1000b2148 0x1000b1e24 0x1000a2dc4 0x1000a2e0c 0x186966e18 0x185a4a8d8 0x185a4a588 0x185a47fd4 0x1859750a4 0x18eb175a4 0x18a2aa3c0 0x1000a6ae8 0x1000a6b28 0x196852a08) libc++abi.dylib:以NSException类型的未捕获异常终止

以下是API提供的OnDevicarrival的代码片段

-(SKTRESULT)handleDeviceArrival:(id<ISktScanObject>)scanObj{
SKTRESULT result=ESKT_NOERROR;
id<ISktScanDevice> scanDevice=[SktClassFactory createDeviceInstance:_scanApi];
NSString* name=[[scanObj Msg]DeviceName];
NSString* guid=[[scanObj Msg]DeviceGuid];
long type=[[scanObj Msg]DeviceType];

// create a new DeviceInfo object
DeviceInfo* deviceInfo=[[DeviceInfo alloc]init:scanDevice name:name type:type];

// open the scanner which means that we can now receive
// any event (such as DecodedData event) from this scanner
result=[scanDevice open:guid];

NSLog(@"!!!device connected!!!!");

if(SKTSUCCESS(result)){
NSLog(@"SKTSUCCESS!");
    if(_noDeviceText!=nil)
        [_deviceInfoList removeObjectForKey:_noDeviceText];

    // add the device info into the list
    [_deviceInfoList setValue:deviceInfo forKey:[NSString stringWithFormat:@"%@",scanDevice]];
    NSLog(@"device info added to list.");
}

// notify the ScanApiHelper user a scanner has connected to this host
NSLog(@"about to notify ScanApiHelper that the scanner has been connected.");

if(_delegate!=nil)
    NSLog(@"delegate is NOT nil");

   [_delegate onDeviceArrival:result Device:deviceInfo];
 NSLog(@"ScanApi has been notified");
enter code here`#if __has_feature(objc_arc)
#else 
[deviceInfo release];// we don't keep this object since we couldn't open the scanner
 NSLog(@"device info released");
#endif
return result;
}
-(SKTRESULT)handleDeviceArrival:(id)scanObj{
SKTRESULT结果=ESKT_NOERROR;
id ScandDevice=[SktClassFactory createDeviceInstance:\u scanApi];
NSString*name=[[scanObj Msg]DeviceName];
NSString*guid=[[scanObj Msg]设备guid];
long type=[[scanObj Msg]设备类型];
//创建新的DeviceInfo对象
DeviceInfo*DeviceInfo=[[DeviceInfo alloc]初始化:扫描设备名称:名称类型:类型];
//打开扫描仪,这意味着我们现在可以接收
//来自此扫描仪的任何事件(如DecodedData事件)
结果=[scanDevice open:guid];
NSLog(@“!!!设备已连接!!!!”);
if(SKTSACCESS(结果)){
NSLog(@“sktsucess!”);
如果(_noDeviceText!=nil)
[_deviceinfo-list-removeObjectForKey:_noDeviceText];
//将设备信息添加到列表中
[_deviceInfo列表集合值:deviceInfo forKey:[NSString stringWithFormat:@“%@”,ScandDevice]];
NSLog(@“设备信息添加到列表中”);
}
//通知ScanApiHelper用户扫描仪已连接到此主机
NSLog(@“即将通知ScanApiHelper扫描仪已连接。”);
如果(_delegate!=nil)
NSLog(@“委托不为零”);
[_delegateondevicearrival:result Device:deviceInfo];
NSLog(“已通知ScanApi”);
在此处输入代码“#如果uu具有u特性(objc_弧)
#否则
[deviceInfo release];//由于无法打开扫描仪,因此无法保留此对象
NSLog(“设备信息发布”);
#恩迪夫
返回结果;
}
日志打印所有内容,包括“委托不为零”


是否有人对在Swift环境中运行的SocketScan SDK有问题,如果有,有什么建议可以解决这个问题?

我也有同样的问题。代表func onDeviceArrival的选择器“Device”在Swift中为小写

将ScanAPI/lib/ScanApiHelper.h(ScanApiHelperDelegate)中的“设备”更改为“设备”,如下所示:

然后更改函数handleDeviceArrival中ScanAPI/lib/ScanApiHelper.mm中的调用

[_delegate onDeviceArrival:result device:deviceInfo];

希望这有帮助

这是Socket Mobile直接提供的修复程序,与Mike的回答一致

ScanApiHelper.h

--- ScanApiHelper.h
+++ ScanApiHelper.h
@@ -70,7 +70,7 @@
  * @param result contains the result of the connection
  * @param newDevice contains the device information
  */
--(void)onDeviceArrival:(SKTRESULT)result Device:(DeviceInfo*)deviceInfo;
+-(void)onDeviceArrival:(SKTRESULT)result device:(DeviceInfo*)deviceInfo;

 /**
  * called each time a device disconnect from the host
@@ -113,7 +113,7 @@
  * the data has been decoded
  * @param decodedData contains the decoded data information
  */
--(void) onDecodedDataResult:(long) result Device:(DeviceInfo*) device DecodedData:(id<ISktScanDecodedData>) decodedData;
+-(void) onDecodedDataResult:(long) result device:(DeviceInfo*) device decodedData:(id<ISktScanDecodedData>) decodedData;

 // THIS IS THE PREVIOUS onDecodedData THAT WE KEEP FOR BACKWARD
 // COMPATIBILITY BUT THE BEST IS TO USE onDecodedDataResult THAT
@@ -125,6 +125,6 @@
  * the data has been decoded
  * @param decodedData contains the decoded data information
  */
--(void) onDecodedData:(DeviceInfo*) device DecodedData:(id<ISktScanDecodedData>) decodedData;
+-(void) onDecodedData:(DeviceInfo*) device decodedData:(id<ISktScanDecodedData>) decodedData;

 @end

杰出的我遇到了与“OnDecodedata”相同的问题,需要类似的修复。感谢您的跟进和发布解决方案。我将其替换为一个统一的变化差异,因为我认为它更容易解析。
--- ScanApiHelper.h
+++ ScanApiHelper.h
@@ -70,7 +70,7 @@
  * @param result contains the result of the connection
  * @param newDevice contains the device information
  */
--(void)onDeviceArrival:(SKTRESULT)result Device:(DeviceInfo*)deviceInfo;
+-(void)onDeviceArrival:(SKTRESULT)result device:(DeviceInfo*)deviceInfo;

 /**
  * called each time a device disconnect from the host
@@ -113,7 +113,7 @@
  * the data has been decoded
  * @param decodedData contains the decoded data information
  */
--(void) onDecodedDataResult:(long) result Device:(DeviceInfo*) device DecodedData:(id<ISktScanDecodedData>) decodedData;
+-(void) onDecodedDataResult:(long) result device:(DeviceInfo*) device decodedData:(id<ISktScanDecodedData>) decodedData;

 // THIS IS THE PREVIOUS onDecodedData THAT WE KEEP FOR BACKWARD
 // COMPATIBILITY BUT THE BEST IS TO USE onDecodedDataResult THAT
@@ -125,6 +125,6 @@
  * the data has been decoded
  * @param decodedData contains the decoded data information
  */
--(void) onDecodedData:(DeviceInfo*) device DecodedData:(id<ISktScanDecodedData>) decodedData;
+-(void) onDecodedData:(DeviceInfo*) device decodedData:(id<ISktScanDecodedData>) decodedData;

 @end
--- ScanApiHelper.mm    
+++ ScanApiHelper.mm    
@@ -1658,7 +1658,7 @@

     // notify the ScanApiHelper user a scanner has connected to this host
     if(_delegate!=nil)
-        [_delegate onDeviceArrival:result Device:deviceInfo];
+        [_delegate onDeviceArrival:result device:deviceInfo];

 #if __has_feature(objc_arc)
 #else 
@@ -1790,14 +1790,14 @@
     result=[[scanObj Msg]Result];
     DeviceInfo* deviceInfo=[self getDeviceInfoFromScanObject:scanObj];
     if(_delegate!=nil){
-        if([_delegate respondsToSelector:@selector(onDecodedDataResult:Device:DecodedData:)]==YES){
-            [_delegate onDecodedDataResult:result Device:deviceInfo DecodedData:[[[scanObj Msg]Event]getDataDecodedData]];
+        if([_delegate respondsToSelector:@selector(onDecodedDataResult:device:decodedData:)]==YES){
+            [_delegate onDecodedDataResult:result device:deviceInfo decodedData:[[[scanObj Msg]Event]getDataDecodedData]];
         }
         else{
             // call only in case of no error the legacy onDecodedData:
             if(SKTSUCCESS(result)){
-                if([_delegate respondsToSelector:@selector(onDecodedData:DecodedData:)]==YES){
-                    [_delegate onDecodedData:deviceInfo DecodedData:[[[scanObj Msg]Event]getDataDecodedData]];
+                if([_delegate respondsToSelector:@selector(onDecodedData:decodedData:)]==YES){
+                    [_delegate onDecodedData:deviceInfo decodedData:[[[scanObj Msg]Event]getDataDecodedData]];
                 }
             }
         }