我正试图在用Swift编写的应用程序中使用SocketScan SDK。使用桥接头,目的-C代码很容易被导入。但是,在运行应用程序时,它会在onDeviceArrival阶段崩溃,Xcode引用“未识别的选择器”。也就是说,ScanApi打开并运行,在设备到达时,应用程序崩溃时会出现以下错误:
-SocketConnect.ViewController onDeviceAr敌:设备:未识别的选择器发送到实例0x15550e670 *终止应用程序,原因是:'NSInvalidArgumentException',原因:'-SocketConnect.ViewController onDeviceAr敌:设备:未识别的选择器发送给实例0x15550e670‘*第一次抛出调用堆栈:(0x185a9259c 0x1961e40e4 0x99a81854x664 0xa230 0x99ab6c0x99b2798 0x1000b2148 0x1000b1e24 xa2dc4 0x1000a2dc4 0x1000a8xa8x4xa8xa8xa8xa8xa8xa8xa8xa8xa8xa8xa8xa8xa8xa8xa8xa8xa8xa8xa8xa8xa8xa8xa8xa8xa8xa8x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4xa8x4xa8x4xa8x4x4x4x4x4x4xa8x4xa8x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4x4184604x4x4x4x99460x4x64x6x9966x6x6x996x6c0x99b6c
下面是API提供的来自onDeviceArrival的代码片段。
-(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(@"!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;
}日志打印到并包括“委托不是零”的所有内容。
是否有人对SocketScan SDK在Swift环境中运行有问题,如果有,有什么建议来解决这个问题吗?
发布于 2014-12-04 14:47:33
我也有同样的问题。选择器"Device“为委托函数onDeviceArrival以小写为Swift。
将ScanAPI/lib/ScanApiHelper.h (ScanApiHelperDelegate)中的“设备”改为“设备”
-(void)onDeviceArrival:(SKTRESULT)result device:(DeviceInfo*)deviceInfo;然后在函数handleDeviceArrival中更改ScanAPI/lib/sccanApiHelper.mm中的调用
[_delegate onDeviceArrival:result device:deviceInfo];希望这能有所帮助!
发布于 2014-12-04 20:55:34
这是直接从Socket提供的补丁,这也符合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;
@endScanApiHelper.mm
--- 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]];
}
}
}https://stackoverflow.com/questions/27222340
复制相似问题