Discovering Printer
The SDK also offers API to discover Brother printers from your application.
Sample Codes
Wi-Fi Printer
You can discover Wi-Fi Printer connected to the same network with the mobile device.
iOS - Objective-C:
@interface YourClass : NSObject<BRPtouchNetworkDelegate> @property (nonatomic, strong) BRPtouchNetworkManager *networkManager; @end @implementation YourClass - (void)startSearchWiFiPrinter { self.networkManager = [BRPtouchNetworkManager new]; self.networkManager.delegate = self; [self.networkManager startSearch:5]; } // BRPtouchNetworkDelegate - (void)didFinishSearch:(BRPtouchNetworkManager *)manager { NSArray<BRPtouchDeviceInfo *> *devices = [manager getPrinterNetInfo]; for (BRPtouchDeviceInfo *deviceInfo in devices) { NSLog(@"Model: %@, IP Address: %@", deviceInfo.strModelName, deviceInfo.strIPAddress); } } @end
iOS - Swift:
class YourClass: NSObject, BRPtouchNetworkDelegate { private var networkManager: BRPtouchNetworkManager? func startSearchWiFiPrinter() { let manager = BRPtouchNetworkManager() manager.delegate = self manager.startSearch(5) self.networkManager = manager } // BRPtouchNetworkDelegate func didFinishSearch(_ sender: Any!) { guard let manager = sender as? BRPtouchNetworkManager else { return } guard let devices = manager.getPrinterNetInfo() else { return } for deviceInfo in devices { if let deviceInfo = deviceInfo as? BRPtouchDeviceInfo { print("Model: \(deviceInfo.strModelName), IP Address: \(deviceInfo.strIPAddress)") } } } }
Android:
void searchWiFiPrinter() { new Thread(new Runnable() { @Override public void run() { Printer printer = new Printer(); NetPrinter[] printerList = printer.getNetPrinters("QL-1110NWB"); for (NetPrinter printer: printerList) { Log.d("TAG", String.format("Model: %s, IP Address: %s", printer.modelName, printer.ipAddress)); } } }).start(); }
Bluetooth Printer
You can retrieve bluetooth printers which are already paired with the mobile device. The SDK offers these API only for iOS.
iOS - Objective-C:
- (NSArray<BRPtouchDeviceInfo *> *)retrieveBluetoothPrinter { return BRPtouchBluetoothManager.sharedManager.pairedDevices; }
iOS - Swift:
func retrieveBluetoothPrinter() -> [BRPtouchDeviceInfo] { let devices = BRPtouchBluetoothManager.shared().pairedDevices() return devices as! [BRPtouchDeviceInfo] }
Bluetooth Low Energy Printer
You can discover nearby Bluetooth Low Energy Printer.
iOS - Objective-C:
- (void)startSearchBLEPrinter { BOOL started = [BRPtouchBLEManager.sharedManager startSearchWithCompletionHandler:^(BRPtouchDeviceInfo *deviceInfo) { NSLog(@"Model: %@, Local Name: %@", deviceInfo.strModelName, deviceInfo.strBLEAdvertiseLocalName); }]; } - (void)stopSearchBLEPrinter { [BRPtouchBLEManager.sharedManager stopSearch]; }
iOS - Swift:
func startSearchBLEPrinter() { let started = BRPtouchBLEManager.shared().startSearch { (deviceInfo: BRPtouchDeviceInfo?) in if let deviceInfo = deviceInfo { print("Model: \(deviceInfo.strModelName), Local Name: \(deviceInfo.strBLEAdvertiseLocalName)") } } } func stopSearchBLEPrinter() { BRPtouchBLEManager.shared().stopSearch() }
Android:
void searchBLEPrinter() { new Thread(new Runnable() { @Override public void run() { Printer printer = new Printer(); List<BLEPrinter> printerList = printer.getBLEPrinters(BluetoothAdapter.getDefaultAdapter(), 30); for (BLEPrinter printer: printerList) { Log.d("TAG", "Local Name: " + printer.localName)); } } }).start(); }
Notes
You don't have to use these APIs if you can get the following identifier of the printer beforehand.
OS | USB | Wi-Fi | Bluetooth | Bluetooth Low Energy |
---|---|---|---|---|
iOS | N/A | IP address | Serial Number | Local Name |
Android | No ID (*1) | IP address or MAC address | Bluetooth device address | Local Name |
- (*1) The connected Brother printer is automatically specified