Printer connectivity issues on iOS 14 devices

// Expert user has replied.
J Jules Robichaud-Gagnon 3 years 7 months ago
82 3 0

There is a racing condition between the initialization of MfiBtPrinterConnection and ZebraPrinterFactory's getInstance that occurs on recent iOS devices.
        connection = [[[MfiBtPrinterConnection alloc] initWithSerialNumber:self.connectivityViewController.bluetoothPrinterLabel.text] autorelease];
        BOOL didOpen = [connection open];
        if(didOpen == YES) {
                // A VERY SHORT DELAY IS NEEDED HERE TO WORK
                NSError *error = nil;
                id printer = [ZebraPrinterFactory getInstance:connection error:&error];
        }
If we wait long enough the error will be "Unable to determine printer language"
The bug may not occur if there are NSLog or other code causing delays. Sometimes the connection seems to stop and a log like this appear:
        2020-10-29 15:13:37.733311-0400 ZSDKDeveloperDemos[2200:457464] CoreAccessories accessoryInfo for departure = {
                ACCExternalAccessoryPPIDKey = "";
                ACCExternalAccessoryPrimaryUUID = "232DDB75-5A99-4076-A1B2-0F58538A0884";
                ACCExternalAccessoryProtocolDetailsKey = {
                        "com.zebra.rawport" = {
                                ACCExternalAccessoryMatchAction = 2;
                                ACCExternalAccessoryProtocolEndpointUUID = "232DDB75-5A99-4076-A1B2-0F58538A0884";
                                ACCExternalAccessoryProtocolIndex = 90;
                                ACCExternalAccessoryProtocolType = 0;
                                ACCExternalAccessorySessionUsesSocketInterfaceKey = 1;
                        };
                };
                IAPAppAccessoryCapabilitiesKey = 1;
                IAPAppAccessoryDockTypeKey = "";
                IAPAppAccessoryFirmwareRevisionKey = 001;
                IAPAppAccessoryFirmwareRevisionPendingKey = "";
                IAPAppAccessoryHardwareRevisionKey = 001;
                IAPAppAccessoryMacAddressKey = "48:A4:93:4F:F7:DF";
                IAPAppAccessoryManufacturerKey = "Zebra Technologies";
                IAPAppAccessoryModelNumberKey = ZQ521;
                IAPAppAccessoryNameKey = XX_HID_SERIAL_NUMBER;
                IAPAppAccessoryProtocolsKey = {
                        "com.zebra.rawport" = 90;
                };
                IAPAppAccessorySerialNumberKey = XX_HID_SERIAL_NUMBER;
                IAPAppAccessoryTransportType = 2;
                IAPAppAccessoryVehicleInfoInitialDataKey = {
                };
                IAPAppConnectionIDKey = 49928821;
        }
== Workaround for the racing condition ==
Add a sleep:
        connection = [[[MfiBtPrinterConnection alloc] initWithSerialNumber:self.connectivityViewController.bluetoothPrinterLabel.text] autorelease];
        BOOL didOpen = [connection open];
        if(didOpen == YES) {
                [NSThread sleepForTimeInterval:0.01f]; // Very short sleep is needed otherwise the printer is not really ready on faster iOS devices
                NSError *error = nil;
                id printer = [ZebraPrinterFactory getInstance:connection error:&error];
        }
But it does not fix the problem, sometimes it will get stuck in                 id printer = [ZebraPrinterFactory getInstance:connection error:&error];.
== Printer ==
- Model: ZQ521
- Firmware: V91.21.05Z
- PDFDirect: v206
- Configurations:
        - apl.enable "pdf"
        - ezpl.media_type "continuous"
== SDK ==
SDK: iOS v1.5.1049
== iOS models ==
- iPhone 12 PRO iOS 14.1
- iPad Air 4 with iOS 14.1
== Steps to reproduce ==
1. Pair printer with iOS device.
2. Open iOS demo
3. In StatusViewController.mm comment lines 97 and 99. Ex:
‎‎        // [self.connectivityViewController setStatus:@"Connected..." withColor:[UIColor greenColor]];
        // [self.connectivityViewController setStatus:@"Determining Printer Language..." withColor:[UIColor yellowColor]];
4. Start app using debugger
5. Press "Start" button
6. Press "Printer Status"
7. Select "Bluetooth"
8. Select printer
9. Press "Check Status"
10. Thread get stuck at line "id printer = [ZebraPrinterFactory getInstance:connection error:&error];" for a while and fail after a while

Please Register or Login to post a reply

3 Replies

S Steven Si

Thanks for sharing the findings. I don't have iPhone 12 Pro to reproduce the issue. This might be something related to iPhone 12 Pro specifically, though I am not 100% sure.
With iPhone 11 Pro & iOS 14.1, we have observed that Bluetooth connection is a little flaky. The Bluetooth connection gets disconnected periodically every 30 to 50 seconds for no reason. Since I don't have iPhone 12 Pro, I cannot be 100% sure if the same iOS bug gets carried over from iPhone 11 Pro. You can simply verify this with your iPhone 12 Pro by opening Settings->Bluetooth and watch if the Bluetooth status radio button along with the entire page blinks roughly every 30 to 50 seconds. When it blinks, it means the iPhone is trying to reestablish the connection, which cause the disconnection briefly. This might be the root cause of the problem you reported above. If this blink happens with iPhone 12 Pro, then we cannot do anything about it on the SDK side.
Below is the screenshot I had with iPhone 11 Pro. I had a number of Bluetooth devices connected. The Bluetooth setting page blinks every 30 or 50 sec.

 
 

J Jules Robichaud-Gagnon

I found this issue: https://developer.zebra.com/community/home/blog/2017/11/01/ios-11-blueto...
The proposed solution on the closure of the the connection did not change anything.

J James Cullis

We have the same issue with both an 11 Pro and 12, but we have an iPhone 8 that works perfectly.
All three are running 14.8

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