iMZ220-MfiBtPrinterConnection::close is slow on IOS10

// Expert user has replied.
S Sergei Yankovskiy 3 years ago
4 8 0

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 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;
}

Please register or login to post a reply

8 Replies

V Vedsatx Saddvv

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.

A Andrea Greggio

Hi i' cannot find the way to change this value, the method not exist in sdk Build: 2.14.5198. In doc thereis only this two methods setMaxTimeoutForRead(int maxTimeoutForRead) setTimeToWaitForMoreData(int timeToWaitForMoreData) .
So how i can set this value?

S Steven Si

It's in the MfiBtPrinterConnection class of the Link-OS SDK for iOS v1.5.1049, where the setTimeToWaitBeforeCloseInMilliseconds: is defined. The quoted version v2.14.5198 is probably referring to the Link-OS SDK for Android, where the 5 second wait time before closing a Bluetooth connection is baked into the SDK and cannot be changed. It's only changeable in the SDK for iOS.

A Andrea Greggio

Thank's for your information..
I think that i have to change my application and create on start a object bluetooth connection that remains the same and are not recreating every time that a method is called.. so i think that i've to create a singelton class to manage bt connection...
thanks

S Steven Si

I don't think we should keep the Bluetooth connection object open all the time, because the object could be outdated once the printer's Bluetooth is out of the range. Secondly, the app doesn't print the label constantly all the time. We suggest to close the Bluetooth connection once the printing is done and reopen the connection when needed. So we don't run into to the situation where the Bluetooth connection object is stalled or outdated.

A Andrea Greggio

My application already works like this, it takes 3 seconds from starting to printing the title and then 5 seconds to close the connection.
The problem is that when I print 5 titles I recall the procedure 5 times and introduce a global delay of 25 seconds.
So I thought of modifying the app by passing the number of titles to be printed, creating the connection object the first time and not closing it until I reached the 5th title. Do you think this is a right way or have other ideas?

S Steven Si

Yes, this is the right approach. When we have a batch of labels to print, we certainly should keep the connection open until the end of the last label of the batch, so we can save the overhead from the open() and close() for each label. Once the app has navigated out of the context of the label printing, then we should certainly close the connection.

A Andrea Greggio

Thanks.. but the logic is 1 ticket .open(), 2,3,4, ticket check if isConnected() ,5 last ticket .close().
It's right or i0ve to using other method zebra sdk?

CONTACT
Can’t find what you’re looking for?