1

Swift で作成されたアプリケーションで SocketScan SDK を使用しようとしています。ブリッジング ヘッダーを使用して、Objective-C コードを簡単にインポートできました。ただし、アプリケーションを実行すると、onDeviceArrival ステージで Xcode が「認識されないセレクター」を引用してクラッシュします。つまり、ScanApi を開いて実行し、デバイスの到着時にアプリケーションが次のエラーでクラッシュします。

-[SocketConnect.ViewController onDeviceArrival:Device:]: 認識されないセレクターがインスタンス 0x15550e670 に送信されました * キャッチされない例外 'NSInvalidArgumentException' によりアプリを終了します。理由: '-[SocketConnect.ViewController onDeviceArrival:Device:]: 認識されないセレクターがインスタンス 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 で問題が発生した人はいますか? もしそうなら、この問題を克服するための推奨事項はありますか?

4

2 に答える 2

1

私も同じ問題を抱えていました。デリゲート関数 onDeviceArrival の Swift では、セレクター「Device」は小文字です。

ScanAPI/lib/ScanApiHelper.h (ScanApiHelperDelegate) の "Device" を "device" に変更します。

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

次に、関数 handleDeviceArrival の ScanAPI/lib/ScanApiHelper.mm の呼び出しを変更します。

[_delegate onDeviceArrival:result device:deviceInfo];

お役に立てれば!

于 2014-12-04T14:47:33.787 に答える
1

これは 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

ScanApiHelper.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]];
                 }
             }
         }
于 2014-12-04T20:55:34.287 に答える