iMZ220-MfiBtPrinterConnection::close is slow on IOS10

When we print a simple label from IOS10 device, the print is instant, but [connection close] call takes several seconds to complete. The same code/library/app works without any delay on older IOS8 phones.

 

Sample code for printing:

 

 

(NSInteger) printFormat:(NSString*)formatString error:(NSError **)error

{

      id<ZebraPrinterConnection, NSObject> connection = [[MfiBtPrinterConnection alloc] initWithSerialNumber:[self serialNumber]];

     BOOL success = [connection open]; //instant

     BOOL isConnected = [connection isConnected]; //instant

     NSInteger bytes = [connection write:[formatString dataUsingEncoding:NSUTF8StringEncoding] error:error]; //instant and print is done

     [connection close]; //3-7seconds to close connection!!!

     return bytes;

}

Anonymous (not verified)
The delay is due to the

The delay is due to the default setting in Link-OS SDK for iOS. The default is 5 seconds. But the delay can be modified by - setTimeToWaitBeforeCloseInMilliseconds:. The 5 seconds delay has been there for awhile in the prior releases. It should not be affected by iOS versions. Please check the API documentation of - setTimeToWaitBeforeCloseInMilliseconds:. Hope this helps.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Sergei Yankovskiy
I've modified the code

I've modified the code accordingly, expecting 100ms delay, but it still takes ~5 seconds to close the connection:

(NSInteger) printFormat:(NSString*)formatString error:(NSError **)error

{

      MfiBtPrinterConnection* connection = [[MfiBtPrinterConnection alloc] initWithSerialNumber:[self serialNumber]];

     [connection setTimeToWaitAfterReadInMilliseconds:100]; //OPTION 1

     BOOL success = [connection open]; //instant

     //[connection setTimeToWaitAfterReadInMilliseconds:100]; //OPTION 2

     BOOL isConnected = [connection isConnected]; //instant

     NSInteger bytes = [connection write:[formatString dataUsingEncoding:NSUTF8StringEncoding] error:error]; //instant and print is done

     [connection close]; //3-7seconds to close connection!!!

     return bytes;

}

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
The API used in the code was

The API used in the code was wrong. It should be setTimeToWaitBeforeCloseInMilliseconds. The setTimeToWaitAfterReadInMillisconds is for changing a different wait time.

{

    MfiBtPrinterConnection* connection = [[MfiBtPrinterConnection alloc] initWithSerialNumber:[self serialNumber]];

    [connection setTimeToWaitBeforCloseInMilliseconds:100]; //OPTION 1

    BOOL success = [connection open]; //instant

    BOOL isConnected = [connection isConnected]; //instant

    NSInteger bytes = [connection write:[formatString dataUsingEncoding:NSUTF8StringEncoding] error:error]; //instant and print is done

    NSLog(@"Before calling close");

    [connection close]; // It should return in 100ms

    NSLog(@"After the close return");

    return bytes;

}

Vote: 
Vote up!
Vote down!

Points: 1

You voted ‘up’


Sergei Yankovskiy
Thank you! I copied wrong

Thank you! I copied wrong method from API docs as it didn't fully scroll to the top.

setTimeToWaitBeforeCloseInMilliseconds works as expected.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments