We are developing a mobile application in which we need to obtain the IP address of the printer connected to the device via Bluetooth in order to perform certain printing-related operations. Currently, we have already developed the solution for Android, but we are experiencing issues with the iOS platform when attempting to obtain the printer's IP address.
We have tried using the ZebraPrinterFactory class provided by the Zebra SDK, specifically the getLinkOsPrinter method, but it resulted in a compilation error on iOS indicating that it is not available. We are using version 1.5.1049 of the SDK. Additionally, we have explored the possibility of using the NetworkDiscoverer class to discover the printer on the network, but we have not found a suitable method to directly obtain the printer's IP address since we do not know the specific range to search for the printer.
We would like to know the recommended way to obtain the IP address of the printer connected to the device. We would greatly appreciate it if you could provide us with information on how we can achieve this using the tools and functions available in the Zebra SDK.
Thanks!
10 Replies
What type of the printer models are you using? What development platform are you using for iOS, i.e., Xamarin or XCode?
For iOS, there is a dedicated library in the Link-OS SDK. To do a network discovery on iOS, you need to have the multicast entitlement from the Apple Developer Program. Without the entitlement, the iOS will block the multicast msg on iOS 14.5 and later.
Hi Steven, sorry for my delayed response.
I'm going to provide some more context to our situation. We are developing an app using Cordova on Xcode, and for printer connectivity, we have developed a plugin that utilizes the LinkOs library provided by Zebra. The printer model we are working with is the ZD410 and similar ones. As I mentioned in the initial post, on Android, we make use of the ZebraPrinterFactory class and its getLinkOsPrinter method. However, the iOS SDK does not provide these methods, and we are unable to retrieve the printer properties.
While reviewing the classes and methods available in the SDK, we discovered NetworkDiscoverer, and we were able to obtain the IP address of the printer connected on the network. However, to do this, we need to know the IP range it is within. For example, in my case, it is 192.168.5.X. But this is not reliable since a client, for example, could have an IP of 10.10.1.X.
That's why we wonder if there is a more efficient way to obtain the IP address of the printer that is already connected via Bluetooth to a new mobile device.
Thank you very much.
Hi Lluis,
Thanks for providing the details. You are correct. The getLinkOsPrinter method was later added to the Link-OS SDK for Android, but it has never been added to the Link-OS SDK for iOS. That's the reason for the compilation error in XCode.
To obtain the IP address of the printer, we can use the SGD GET. Once the device is connected to the printer, we can call the SGD GET of interface.network.active.ip_addr to get the IP address alone of the printer, or the SGD GET of interface.network.active to get the complete information of the network connectivity.
If the *ipAddress is empty, it means the printer is not network connected.
Hi Steven,
Thank you for your help.
The code you provided is in Objective-C, but the plugin we are developing is in Swift. I have tried to adapt the suggested call, but I keep encountering errors. I'm attaching the code for the function where I make the printer status call and a small function where I make the call you suggested.
But when I try to compile, the following errors appear:
error: type of expression is ambiguous without more context
DispatchQueue.global(qos: .background).async {
Referring to the first line of the getIPPrinter function.
Can you help me?
I'm not very knowledgeable in Swift or Objective-C, and we're adapting an existing plugin for the functionality we need.
Thank you very much.
You should be able to call the Objective-C API from Swift through the Bridging Header. Please include the following header files in the Bridging Header
Hi Steven,
Yes I include all these files on Bridging Header
Not sure if the ambiguous expression error is due to the unnecessary headers in the Bridging Header. Please limit the header files and place them in the order as shown in the following.
Hello Steven,
I have been trying what you have been saying in your posts and I have not been able to make any progress.
I still have the problem of ambiguous expression error.
Reviewing the SGD.h class I have seen that there are two GET methods. I leave below the file, but it is the same that Zebra indicates you to make use of the SDK.
If I try to comment one of the two GET methods I still get the same error, but if I comment both of them then it tells me that the GET method does not exist.
The truth is that I am very blocked and I don't know where to advance.
I comment you because we need the IP of the printer, to see if you can think of another way to be able to make the development that we want.
Our client wants to be able to print with the Zebra printer either by WIFI or Bluetooth. In the past with the application they are using right now they have problems that the printer is blocked when printing by bluetooth and that is why they ask us to make their new application to have the ability to print in both configurations. So to get the IP, when the printer is not yet configured to the network, is to send it a network connection configuration template. I wait for it to reboot and once it has rebooted and connected correctly to the network I try to get from its configuration that information.
As I told you in Android the solution was with the ZebraPrinterFactory class.
See if with this you can tell me what next steps to try or follow.
Thank you very much
Hi Lluis,
We will look into the ambiguous expression issue thrown out from Swift later. In the meantime, an alternative is to use the sendAndWaitForResponse API by sending the SGD command string, which is "! U1 getvar \"interface.network.active.ip_addr\"\n\r". It should return a string that contains the ip address of the printer.
Hi Steven,
I would try that. I will update if I get finally the IP :P
Thnks!