cordova-brother-label-printer icon indicating copy to clipboard operation
cordova-brother-label-printer copied to clipboard

Add Bluetooth Support for iOS, extend support for Android

Open Ayiga opened this issue 7 years ago • 7 comments

Greetings @gordol

With this update, I've been able to add Bluetooth printing support for iOS. On both platforms, in order for a printer to show up in the lists returned by findBluetoothPrinters and findPrinters, the printer must first be paired. On iOS this spawns a modal window that we don't really have control over, or the ability to interact with. Unfortunately, this means we can't guarantee a meaningful callback for a user cancelling the pairing process. As such, I've added a new method called pairBluetoothPrinters to help facilitate this.

On Android pairBluetoothPrinters just opens the Bluetooth Settings area, on iOS it spawns the aforementioned modal. The callback returns immediately and doesn't reflect any selection, pairing result, or cancellation.

As an aside, I've been thinking about adding a function that can be registered to get informed about Bluetooth Accessory connections. (Perhaps one for disconnections too), but I haven't needed it for now.

I've also taken the opportunity to add failure callbacks for most of the printing methods. I figure this will make it more consistent and easier to chain off of when it comes to failures as well as successes.

I have created an Error system that allows for an Error namespace, code, and message. I haven't really finalized any of these things, and perhaps it's something we can agree on before forcing it.

I have adjusted the Readme accordingly, and cleaned it up a little bit as well. I added a TODO section and put two things in it at the moment. I added the USB into the TODO because I'm not really familiar with it, and I know it's kind of hard-coded for your situation at the moment. However, it should probably be configured to allow for others to be able to use it with other printers as well.

Likely one of the next things I'll be working on is a way to select the device's printing paper type.

Please let me know if you have any questions,

Thanks,

~ Ayiga

Ayiga avatar Sep 11 '17 22:09 Ayiga

Thanks, I'll review this soon... I'll try to get to it this week; I need to dust off, and charge my old iPad and update Xcode probably.

I added the USB into the TODO because I'm not really familiar with it, and I know it's kind of hard-coded for your situation at the moment.

The only thing that's hard-coded is the model configuration... We should be able to make that configurable, I think.

gordol avatar Sep 11 '17 22:09 gordol

Please hold off on any potential merge. I have a crash on iOS right now.

Ayiga avatar Sep 11 '17 22:09 Ayiga

for sure... no worries. i haven't even tested yet :)

gordol avatar Sep 11 '17 22:09 gordol

Okay I was able to fix the issue and able to print on iOS again... I had a hell of a time chasing this down, all because I changed the name of a variable :\ .

Ayiga avatar Sep 12 '17 02:09 Ayiga

good to hear. i have my ipad charged, but i need to get my xcode environment sorted out... my ipad is running ios8.1 though. do you know if this is only compatible with specific IOS versions?

anyway... looks good. i skimmed the IOS bits... need to brush up on my objc a little, but it looks okay from a high level. proper use of background threads and what-not. however, should pairBluetoothPrinters run in the foreground?

gordol avatar Sep 13 '17 05:09 gordol

I was playing with the Background thread stuff yesterday. Honestly, findNetPrinters on iOS doesn't work unless it's on a foreground thread.

pairBluetoothPrinters just spawns a modal, so it's not actually long running.

findBluetoothPrinters just returns the current list of paired printers on both platforms, so that's not long running either. However, it could be made to run on a background thread on iOS without any issue.

The other thing that is able to run in a background thread is printViaSDK on iOS. Running that in a background thread causes no issues. Although the print operation itself is running in an NSOperationQueue that is using the main thread. That could be tested to see if it has to be in the main queue or not. But, as of now I haven't quite tested that portion.

I looked up the supported iOS versions, it seems to be iOS 6 - iOS 10. It'll probably work on iOS 11, barring any large changes.

Ayiga avatar Sep 13 '17 16:09 Ayiga

Good to know, thanks!

gordol avatar Sep 13 '17 16:09 gordol