gpt4 book ai didi

objective-c - Socket Mobile SocketScan SDK 和 Swift

转载 作者:行者123 更新时间:2023-11-28 05:32:31 29 4
gpt4 key购买 nike

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

-[SocketConnect.ViewController onDeviceArrival:Device:]: unrecognized selector sent to instance 0x15550e670 * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SocketConnect.ViewController onDeviceArrival:Device:]: unrecognized selector sent to instance 0x15550e670' * First throw call stack: (0x185a9259c 0x1961e40e4 0x185a99664 0x185a96230 0x18599ab6c 0x1000b2798 0x1000b2148 0x1000b1e24 0x1000a2dc4 0x1000a2e0c 0x186966e18 0x185a4a8d8 0x185a4a588 0x185a47fd4 0x1859750a4 0x18eb175a4 0x18a2aa3c0 0x1000a6ae8 0x1000a6b28 0x196852a08) libc++abi.dylib: terminating with uncaught exception of type NSException

这是 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(@"!!!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;
}

日志打印所有内容,包括“delegate is NOT nil”。

有没有人遇到过在 Swift 环境中运行的 SocketScan SDK 的问题,如果有,有什么解决这个问题的建议吗?

最佳答案

我遇到了同样的问题。对于委托(delegate)函数 onDeviceArrival,选择器“Device”在 Swift 中是小写的。

将 ScanAPI/lib/ScanApiHelper.h (ScanApiHelperDelegate) 中的“设备”更改为“设备”

-(void)onDeviceArrival:(SKTRESULT)result device:(DeviceInfo*)deviceInfo;

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

[_delegate onDeviceArrival:result device:deviceInfo];

希望这对您有所帮助!

关于objective-c - Socket Mobile SocketScan SDK 和 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27222340/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com