diff --git a/README.md b/README.md index 32536d6..0202416 100644 --- a/README.md +++ b/README.md @@ -61,9 +61,49 @@ __Tested models:__ `QL-720NW`, `QL-820NWB`, `TD-2120N` ## Supported interfaces (by this plugin): * Wi-Fi (Infrastructure mode) -* Bluetooth (Android only, at the moment, iOS needs more work. See [PR10](https://github.com/gordol/cordova-brother-label-printer/pull/10) +* Bluetooth (Android and iOS) * USB +### BlueTooth notes: +If your app is supporting BlueTooth, you will need the following changes in you rproject: +#### Android permissions +``` + + + +``` +#### iOS + +* For iOS, you need to apply for an MFi PPID. +Please follow the steps at +https://secure6.brother.co.jp/mfi/Top.aspx + +* Code change in your cordova config + +``` + + Bluetooth access for Brother label printer + + + Bluetooth access for Brother label printer + + + + com.brother.ptcbp + + + + Used to discover printers on your network + + + + _printer._tcp + _pdl-datastream._tcp + _ipp._tcp + + +``` + ## Usage diff --git a/package.json b/package.json index bf6f1e0..433ebc5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-brother-label-printer", - "version": "1.5.6", + "version": "1.6.0", "description": "Cordova plugin for brother label printers", "cordova": { "id": "cordova-plugin-brother-label-printer", diff --git a/plugin.xml b/plugin.xml index ac885b6..6b25913 100644 --- a/plugin.xml +++ b/plugin.xml @@ -3,7 +3,7 @@ + version="1.6.0"> BrotherPrinter diff --git a/src/ios/BRBluetoothPrintOperation.h b/src/ios/BRBluetoothPrintOperation.h index 8a99133..438b997 100644 --- a/src/ios/BRBluetoothPrintOperation.h +++ b/src/ios/BRBluetoothPrintOperation.h @@ -5,9 +5,8 @@ // Created by Kusumoto Naoki on 2015/08/18. // Copyright (c) 2015年 Kusumoto Naoki. All rights reserved. // -/* #import -#import +#import @interface BRBluetoothPrintOperation : NSOperation { } @@ -20,4 +19,3 @@ numberOfPaper:(int)targetNumberOfPaper serialNumber:(NSString *)targetSerialNumber; @end -*/ diff --git a/src/ios/BRBluetoothPrintOperation.m b/src/ios/BRBluetoothPrintOperation.m index 9971825..ab95078 100644 --- a/src/ios/BRBluetoothPrintOperation.m +++ b/src/ios/BRBluetoothPrintOperation.m @@ -5,7 +5,7 @@ // Created by Kusumoto Naoki on 2015/08/18. // Copyright (c) 2015年 Kusumoto Naoki. All rights reserved. // -/* + #import "BRUserDefaults.h" #import "BRBluetoothPrintOperation.h" @@ -81,4 +81,3 @@ -(void)main { } @end -*/ diff --git a/src/ios/BRUserDefaults.h b/src/ios/BRUserDefaults.h index dfd418a..2105b0c 100644 --- a/src/ios/BRUserDefaults.h +++ b/src/ios/BRUserDefaults.h @@ -49,6 +49,14 @@ enum PrintPaperSize Legal }; +// Item 3 + #define kPrintOrientationKey @"PrintOrientationKey" + enum PrintOrientationKey + { + Landscape = 0x00, + Portrate = 0x01 + }; + // Item 4 #define kScalingModeKey @"ScalingModeKey" enum PrintFitKey diff --git a/src/ios/BrotherPrinter.m b/src/ios/BrotherPrinter.m index 13c8102..832e42d 100644 --- a/src/ios/BrotherPrinter.m +++ b/src/ios/BrotherPrinter.m @@ -270,7 +270,8 @@ - (void)setPrinter:(CDVInvokedUrlCommand *)command { NSString *numberOfCopies = obj[@"numberOfCopies"]; NSString *orientation = obj[@"orientation"]; NSString *customPaperFilePath = obj[@"customPaperFilePath"]; - + NSString *serialNumber = obj[@"serialNumber"]; + if (!modelName) { [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Expected a \"modelName\" key in the given object"] @@ -290,12 +291,23 @@ - (void)setPrinter:(CDVInvokedUrlCommand *)command { } if ([@"BLUETOOTH" isEqualToString:port]) { + + if(!serialNumber){ + [self.commandDelegate + sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Expected a \"serialNumber\" key in the given object for BlueTooth devices"] + callbackId:command.callbackId]; + return; + } [userDefaults setObject:@"0" forKey:kIsWiFi]; [userDefaults setObject:@"1" forKey:kIsBluetooth]; + + [userDefaults + setObject:serialNumber + forKey:kSerialNumber]; } if ([@"NET" isEqualToString:port]) { @@ -305,16 +317,16 @@ - (void)setPrinter:(CDVInvokedUrlCommand *)command { [userDefaults setObject:@"0" forKey:kIsBluetooth]; + + [userDefaults + setObject:@"0" + forKey:kSerialNumber]; } [userDefaults setObject:ipAddress forKey:kIPAddress]; - [userDefaults - setObject:@"0" - forKey:kSerialNumber]; - if (paperLabelName) { [userDefaults setObject:paperLabelName @@ -410,7 +422,7 @@ - (void)printViaSDK:(CDVInvokedUrlCommand *)command { NSString *numPaper = [self stringValueFromDefaults:userDefaults forKey:kPrintNumberOfPaperKey withFallback:@"1"]; // Item 1 printInfo.strPaperName = [self stringValueFromDefaults:userDefaults forKey:kPaperLabelName withFallback:@"62mm"]; // Item 2 - printInfo.nOrientation = (int) [self integerValueFromDefaults:userDefaults forKey:kPrintOrientationKey withFallback:0x00]; // Item 3 + printInfo.nOrientation = (int) [self integerValueFromDefaults:userDefaults forKey:kPrintOrientationKey withFallback:Landscape]; // Item 3 printInfo.nPrintMode = (int) [self integerValueFromDefaults:userDefaults forKey:kScalingModeKey withFallback:Fit]; // Item 4 printInfo.scaleValue = [self doubleValueFromDefaults:userDefaults forKey:kScalingFactorKey withFallback:1.0]; // Item 5 /////////// @@ -501,7 +513,7 @@ - (void)printViaSDK:(CDVInvokedUrlCommand *)command { finalDeviceName = [NSString stringWithFormat:@"Brother %@", printerName]; } }]; - + NSFileManager *fileManager = [NSFileManager defaultManager]; if (isBluetooth == 1) { @@ -510,12 +522,13 @@ - (void)printViaSDK:(CDVInvokedUrlCommand *)command { if ([fileManager fileExistsAtPath:_customPaperFilePath]){ [_ptp setCustomPaperFile:_customPaperFilePath]; } -// [_ptp setupForBluetoothDeviceWithSerialNumber:serialNumber]; + + [_ptp setupForBluetoothDeviceWithSerialNumber:serialNumber]; } else if (isWifi == 1) { _ptp = [[BRPtouchPrinter alloc] initWithPrinterName:finalDeviceName interface:CONNECTION_TYPE_WLAN]; - - if ([fileManager fileExistsAtPath:_customPaperFilePath]){ + + if ([fileManager fileExistsAtPath:_customPaperFilePath]){ [_ptp setCustomPaperFile:_customPaperFilePath]; } // [_ptp setIPAddress:ipAddress]; @@ -536,25 +549,25 @@ - (void)printViaSDK:(CDVInvokedUrlCommand *)command { NSOperation *operation = nil; if (isBluetooth == 1) { - /* BRBluetoothPrintOperation *bluetoothPrintOperation = [[BRBluetoothPrintOperation alloc] - initWithOperation:_ptp - printInfo:printInfo - imgRef:[_image CGImage] - numberOfPaper:[numPaper intValue] - serialNumber:serialNumber]; - - [bluetoothPrintOperation addObserver:self - forKeyPath:@"isFinishedForBT" - options:NSKeyValueObservingOptionNew - context:nil]; + BRBluetoothPrintOperation *bluetoothPrintOperation = [[BRBluetoothPrintOperation alloc] + initWithOperation:_ptp + printInfo:printInfo + imgRef:[_image CGImage] + numberOfPaper:[numPaper intValue] + serialNumber:serialNumber]; + + [bluetoothPrintOperation addObserver:self + forKeyPath:@"isFinishedForBT" + options:NSKeyValueObservingOptionNew + context:nil]; + + [bluetoothPrintOperation addObserver:self + forKeyPath:@"communicationResultForBT" + options:NSKeyValueObservingOptionNew + context:nil]; + + operation = bluetoothPrintOperation; - [bluetoothPrintOperation addObserver:self - forKeyPath:@"communicationResultForBT" - options:NSKeyValueObservingOptionNew - context:nil]; - - operation = bluetoothPrintOperation; - */ } else if (isWifi == 1) { BRWLANPrintOperation *wlanPrintOperation = [[BRWLANPrintOperation alloc] initWithOperation:_ptp @@ -655,19 +668,19 @@ - (void)observeValueForKeyPath:(NSString *)keyPath return; } } else if ([keyPath isEqualToString:@"communicationResultForBT"]) { - /* BRBluetoothPrintOperation *bluetoothOperation = (BRBluetoothPrintOperation *) operation; - BOOL result = bluetoothOperation.communicationResultForBT; - NSLog(@"Communication Result: %d", result); - if (!result) { - [operation removeObserver:self forKeyPath:@"isFinishedForBT"]; - [operation removeObserver:self forKeyPath:@"communicationResultForBT"]; - PTSTATUSINFO resultStatus = bluetoothOperation.resultStatus; - [self.commandDelegate - sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Error occured while Bluetooth printing"] - callbackId:_printCallbackId]; - _printCallbackId = nil; - _image = nil; - }*/ + BRBluetoothPrintOperation *bluetoothOperation = (BRBluetoothPrintOperation *) operation; + BOOL result = bluetoothOperation.communicationResultForBT; + NSLog(@"Communication Result: %d", result); + if (!result) { + [operation removeObserver:self forKeyPath:@"isFinishedForBT"]; + [operation removeObserver:self forKeyPath:@"communicationResultForBT"]; + PTSTATUSINFO resultStatus = bluetoothOperation.resultStatus; + [self.commandDelegate + sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Error occured while Bluetooth printing"] + callbackId:_printCallbackId]; + _printCallbackId = nil; + _image = nil; + } } else { [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; }