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;
}
iMZ220-MfiBtPrinterConnection::close is slow on IOS10// Expert user has replied. |
8 Replies
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.
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?
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.
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
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.
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?
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.
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?