ZebraDevs / LinkOS-Xamarin-Samples

Sample code for developing cross-platform applications on Android and iOS using Xamarin. The demos in this repository are stored on separate branches. To navigate to a demo, please click branches.
Other
8 stars 11 forks source link

Cannot enumerate printers on iOS #3

Closed mrbelk closed 6 years ago

mrbelk commented 6 years ago

I am having a very hard time enumerating bluetooth printers on iOS (iPhone 5, iOS 10.3.3, Xamarin.iOS 11.6.1.2).

I set up a "PrinterDiscovery" class as per the sample, but when I call the BluetoothDiscoverer.Current.FindPrinters(), it immediately fires the OnDiscoveryFinished event and never fires the OnFoundPrinter. I am doing the same thing in Android (this is a Xamarin.Forms project) and I can enumerate the available printers just fine.

Here is the code that I am using:

        public async Task<List<Tuple<string, string>>> GetPairedPrinters()
        {
            IDiscoveryEventHandler btHandler = DiscoveryHandlerFactory.Current.GetInstance();

            List<Tuple<string, string>> _foundPrinters = new List<Tuple<string, string>>();

            var finished = false;

            btHandler = DiscoveryHandlerFactory.Current.GetInstance();
            btHandler.OnFoundPrinter += (handler, discoveredPrinter) => {
                IDiscoveredPrinterBluetooth btPrinter = discoveredPrinter as IDiscoveredPrinterBluetooth;

                _foundPrinters.Add(new Tuple<string, string>(btPrinter.Address, btPrinter.FriendlyName));
            };

            btHandler.OnDiscoveryFinished += (handler) => {
                finished = true;
            };

            btHandler.OnDiscoveryError += (handler, message) => {
                finished = true;
            };

            BluetoothDiscoverer.Current.FindPrinters(null, btHandler);

            await Task.Delay(500);

            while (!finished)
            {
                await Task.Delay(100);
            }

            return _foundPrinters;
        }

I'm completely baffled as to why this won't work on iOS. For the record, I am trying to connect to a QLn420 with the MFI chipset.

Thanks, Matthew Belk

mrbelk commented 6 years ago

So I noticed that the LinkOS_SDK is not technically supported on an iPhone 5, so I tried the same thing on an iPhone 7 (iOS 11.2.1) and got the same result.

mrbelk commented 6 years ago

so, I was able to successfully compile and run the xamarin sample app on my iPhone 7. My actual app doesn't do anything any differently, so I am baffled as to why the difference in behavior.

Robin-West commented 6 years ago

Hi Matthew, So the sample shows the printers enumerating and your app doesn't? Or do neither of them enumerate the printers?

Robin

mrbelk commented 6 years ago

The sample app worked on my iPhone 7

Matthew Belk BizSpeed, Inc 678-287-3315


From: Robin West notifications@github.com Sent: Tuesday, December 19, 2017 5:39:02 PM To: Zebra/LinkOS-Xamarin-Samples Cc: Matthew R. Belk; Author Subject: Re: [Zebra/LinkOS-Xamarin-Samples] Cannot enumerate printers on iOS (#3)

Hi Matthew, So the sample shows the printers enumerating and your app doesn't? Or do neither of them enumerate the printers?

Robin

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/Zebra/LinkOS-Xamarin-Samples/issues/3#issuecomment-352908356, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABCkDwOSsHMuoLKchcpECBac9Hv6TO0kks5tCDsGgaJpZM4RHl-R.

Robin-West commented 6 years ago

OK - Few things to check.

  1. Did you pair the printer in the iOS settings? I'm assuming you did due to the fact that the other app is working.
  2. Did you update your info.plist file? This is similar to an Android Manifest file for iOS. See the documentation here for details. In the iOS Project Settings and Configuration section. Or you can take a look at the file on the sample app.
mrbelk commented 6 years ago

this might be my oversight. I didn't transfer over the UISupportedExternalAcccessoryProtocols or the UIBackgroundMode keys from the info.plist

mrbelk commented 6 years ago

We can close this out because I'm an idiot. Everything looks good now. Thanks for pointing those plist entries out for me.

Robin-West commented 6 years ago

No Problem... The number of times I forgot the manifest or plist when doing live demo coding.... Not fun.