iOS Swift Sample Xcode Projects

// Expert user has replied.
J Justin Leger 1 year 5 months ago
697 11 0

Hi, I looking at doing a mobile printing Proof of Concept and product / technical evaluation using the ZQ511 and ZQ521.

We are primarily an iOS development team and looking for some good Swift sample starter projects to get us up an running quickly with our technical evaluation.

We have found a few sample projects on ZebraDev GitHub, but they are all 6 years old and written in Objective-C. We can definitely look at converting to Swift, but the effort in conversion limits out time and focus.

Sample Project Found

  • LinkOS-SDK: https://github.com/ZebraDevs/LinkOS-iOS-Samples/tree/ZSDK_DevDemos
  • BLE Demo: https://github.com/ZebraDevs/LinkOS-iOS-Samples/tree/ZebraPrinterBLEDemo

We are open to both possible solution of using iOS native BLE connection or using the LinkOS SDK. Zebra has provide us with a pre-release compiled version of the LinkOS SDK to run on newer devices, but there are no Swift project to get started with.

Technical Evaluation Success Criteria

  • iPhone or iPad connection to a printer.
  • Auto re-connection from mobile device to printer. (After things like mobile device sleep/wake or battery replacement on printer)
  • Printing documents (mobile device generated such as PDFs or mapping data to a Zebra template)
  • Printer status information. (Battery Level, Print Medial Levels, etc...)
Please Register or Login to post a reply

11 Replies

S Steven Si

We don't have Swift sample code for the Link-OS SDK for iOS. With the bridging header, the objective-c library of the SDK should work with the latest Swift on the latest iOS devices (iPhone & iPad). The SDK supports connectivity of TCP and Bluetooth Classic. Unfortunately, the SDK doesn't support BLE at the moment. You would need to create your own BLE support.

The Bluetooth auto-reconnection for iOS is already built into the printer's firmware. By default, the Bluetooth auto-reconnection is enabled.

For PDF print, you can take the advantage of the PDF Direct, which is a emulation feature on the printer. The ZQ511, ZQ521 and all Link-OS printers have the PDF Direct capability, which can be enabled or disabled. With a PDF Direct enabled printer, the app simply calls the sendFileContents API to send a PDF file to the printer to print. There is no need to do any conversion at the app level.

With the SDK, we can get the full operational status of the printer, such as the head open, media out, etc. For the printer's battery level, there is a full set of ZPL commands for retrieving the battery related info. For the media level, the app would need to use the printer odometers to estimate the remaining media level roughly based on the initial total number of the labels on the media roll at the installation and the number of labels printed since.

J Justin Leger

Steven, thanks you for getting back with us.

I have converted the BLE Demo to swift and very time I try writing to the ZQ511 I get an Authentication is insufficient error.
Error?    domain: "CBATTErrorDomain" - code: 5    0x000000028164e040

Could this be a printer configuration issue or MFi?

Any help would be greatly appreciated.

Thanks,

Justin

S Steven Si

The issue has nothing to do with MFi, as MFi is not applicable to Bluetooth Low Energy. It's most likely related to the Bluetooth security settings on the ZQ511 printer. Make sure the bluetooth.minimum_security_mode is set to 1. Use the following SGD commands to set and verify the security mode setting for Bluetooth.

### Verify the security mode setting on the printer
! U1 getvar "bluetooth.minimum_security_mode"

### If the return of the above command is not 1, then set it to 1.
! U1 setvar "bluetooth.minimum_security_mode" "1"

 

J Justin Leger

Just to note, I am connecting successfully to the device via BLE in both  the demo app and some custom code version based on the swift conversion.

From my Custom Swift code

  • READ INFO from device ZQ511
  • READ INFO from device XXRAN230900085
  • READ INFO from device V91.21.20Z
  • READ INFO from device ZQ51-BUW0000-00
  • READ INFO from device 6.7
  • READ INFO from device Zebra Technologies

 

From the Converted Obj-C -> Swift App

Image removed.

S Steven Si

These values are from the BLE advertisement packets. The security mode controls the read from and write to the characteristics. This is where the exception occurs if the security mode on the printer is not set properly.

J Justin Leger

Thanks, I think I was resolving this at the same time you were responding. I used the Setup Utility and used the Bluetooth Connectivity Wizard  to set the minimum security value.

I found it in this doc. Table 3 of the security section.

https://www.zebra.com/content/dam/zebra_new_ia/en-us/manuals/printers/common/network/bluetooth-ug-en.pdf

J Justin Leger

I am able to connect and write with the Authentication error now!!!! Yeah!!!

But all my ZPL code is just printing as plain text. Is there another setting that needs to be set?

I am using Labelary to create the ZPL string, covert string to data, break data into chunks based on the peripheral maximumWriteValueLength, then loop through and send the chunks via

self.selectedPeripheral?.writeValue(chunk, for: writeCharacteristicUUID, type: .withResponse)

Anything I might be missing?

 

J Justin Leger

Image removed.

S Steven Si

The device.languages on your ZQ511 printer is set to line_print mode, which results in the ZPL being printed instead of a label. You can use the same Printer Setup Utility app to change the device language setting from the line_print to ZPL, which will solve the issue.

J Justin Leger
Thanks,

Googled you notes and found this link, and it worked! Thanks!

https://supportcommunity.zebra.com/s/article/Change-printer-language-and-driver-to-ZPL?language=en_US

! U1 setvar "device.languages" "zpl"
! U1 setvar "device.pnp_option" "zpl"
! U1 do "device.reset" "" <CR>
W William Mays

Will we ever get native swift support? I am having issues with multiple Xcode and swift projects where I will print a tag, then 10m later it will randomly print the same tag again. Not sure why this is happening. I have closed the printer connection so any ideas?

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