Removed the callback
property from the print
interface
This commit is contained in:
parent
9463786343
commit
1a40324682
34
README.md
34
README.md
@ -25,8 +25,9 @@ cordova plugin rm de.appplant.cordova.plugin.printer
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Release Notes
|
## Release Notes
|
||||||
#### Version 0.4.1 (not yet released)
|
#### Version 0.5.0 (not yet released)
|
||||||
- Release under the Apache 2.0 license.
|
- Release under the Apache 2.0 license.
|
||||||
|
- [***change:***] Removed the `callback` property from the `print` interface.
|
||||||
|
|
||||||
#### Version 0.4.0 (24.08.2013)
|
#### Version 0.4.0 (24.08.2013)
|
||||||
- [feature]: Added Android support<br>
|
- [feature]: Added Android support<br>
|
||||||
@ -60,23 +61,16 @@ window.plugin.printer.isServiceAvailable(
|
|||||||
```
|
```
|
||||||
|
|
||||||
### print()
|
### print()
|
||||||
Function takes an html string and (optionally) a callback function. Optionally you can assign the scope in which the callback will be executed as a third parameter (default to *window*).
|
Function takes an html string.
|
||||||
|
|
||||||
|
**Note:** All required CSS rules needs to be included as well.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Get HTML string
|
// Get HTML string
|
||||||
var page = document.body.innerHTML;
|
var page = document.body.innerHTML;
|
||||||
|
|
||||||
/*
|
// Pass the HTML
|
||||||
* Pass an HTML and - optionally - a callback function.
|
window.plugin.printer.print(page);
|
||||||
*/
|
|
||||||
window.plugin.printer.print(page, function (code) {
|
|
||||||
switch (code) {
|
|
||||||
case 0: // printing cancelled (cancel button pressed)
|
|
||||||
case 2: // printed
|
|
||||||
case 3: // printing failed
|
|
||||||
case 4: // page not printed (something wrong happened e.g. service is not available)
|
|
||||||
}
|
|
||||||
}, this);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Platform specifics
|
## Platform specifics
|
||||||
@ -94,7 +88,7 @@ window.plugin.printer.isServiceAvailable(
|
|||||||
### Specify printing app on Android
|
### Specify printing app on Android
|
||||||
An App-ID can be assigned as a platform configuration to indicate which 3rd party printing app shall be used. Otherwise the first found application will be used.
|
An App-ID can be assigned as a platform configuration to indicate which 3rd party printing app shall be used. Otherwise the first found application will be used.
|
||||||
```javascript
|
```javascript
|
||||||
window.plugin.printer.print(page, null, this, { appId: 'epson.print' });
|
window.plugin.printer.print(page, { appId: 'epson.print' });
|
||||||
```
|
```
|
||||||
|
|
||||||
## Quirks
|
## Quirks
|
||||||
@ -125,18 +119,6 @@ Printing is only supported on AirPrint-enabled printers or with the use of third
|
|||||||
- AirPrint-enabled printers: http://www.apple.com/ipad/features/airprint.html
|
- AirPrint-enabled printers: http://www.apple.com/ipad/features/airprint.html
|
||||||
- Enabling AirPrint on your computer: http://reviews.cnet.com/8301-19512_7-20023976-233.html, or http://www.ecamm.com/mac/printopia/
|
- Enabling AirPrint on your computer: http://reviews.cnet.com/8301-19512_7-20023976-233.html, or http://www.ecamm.com/mac/printopia/
|
||||||
|
|
||||||
### TypeError: Cannot read property 'currentVersion' of null
|
|
||||||
Along with Cordova 3.2 and Windows Phone 8 the `version.bat` script has to be renamed to `version`.
|
|
||||||
|
|
||||||
On Mac or Linux
|
|
||||||
```
|
|
||||||
mv platforms/wp8/cordova/version.bat platforms/wp8/cordova/version
|
|
||||||
```
|
|
||||||
On Windows
|
|
||||||
```
|
|
||||||
ren platforms\wp8\cordova\version.bat platforms\wp8\cordova\version
|
|
||||||
```
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
1. Fork it
|
1. Fork it
|
||||||
|
@ -340,15 +340,4 @@ public class Printer extends CordovaPlugin {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
|
||||||
super.onActivityResult(requestCode, resultCode, intent);
|
|
||||||
|
|
||||||
if (resultCode == -1) {
|
|
||||||
ctx.success(4);
|
|
||||||
} else {
|
|
||||||
ctx.success();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,6 @@
|
|||||||
|
|
||||||
#import "APPPrinter.h"
|
#import "APPPrinter.h"
|
||||||
|
|
||||||
#define APP_PRINT_CANCELLED 0 // Printing cancelled (cancel button pressed)
|
|
||||||
#define APP_PRINT_SENT 2 // Page printed
|
|
||||||
#define APP_PRINT_FAILED 3 // Printing failed
|
|
||||||
#define APP_PRINT_NOTSENT 4 // Page not printed (something wrong happened)
|
|
||||||
|
|
||||||
@interface APPPrinter (Private)
|
@interface APPPrinter (Private)
|
||||||
|
|
||||||
// Erstellt den PrintController
|
// Erstellt den PrintController
|
||||||
@ -65,7 +60,6 @@
|
|||||||
{
|
{
|
||||||
if (![self isPrintServiceAvailable])
|
if (![self isPrintServiceAvailable])
|
||||||
{
|
{
|
||||||
[self informAboutResult:APP_PRINT_FAILED callbackId:command.callbackId];
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,14 +72,10 @@
|
|||||||
[self loadContent:content intoPrintController:controller];
|
[self loadContent:content intoPrintController:controller];
|
||||||
|
|
||||||
[controller presentAnimated:YES completionHandler:^(UIPrintInteractionController* printController, BOOL completed, NSError* error) {
|
[controller presentAnimated:YES completionHandler:^(UIPrintInteractionController* printController, BOOL completed, NSError* error) {
|
||||||
if (completed) {
|
|
||||||
[self informAboutResult:APP_PRINT_SENT callbackId:command.callbackId];
|
|
||||||
} else if (error) {
|
|
||||||
[self informAboutResult:APP_PRINT_FAILED callbackId:command.callbackId];
|
|
||||||
} else {
|
|
||||||
[self informAboutResult:APP_PRINT_CANCELLED callbackId:command.callbackId];
|
|
||||||
}
|
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
[self commandDelegate];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -129,17 +119,6 @@
|
|||||||
controller.showsPageRange = YES;
|
controller.showsPageRange = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Ruft den Callback auf und informiert diesen über den das Ergebnis des Druckvorgangs.
|
|
||||||
*/
|
|
||||||
- (void) informAboutResult:(int)code callbackId:(NSString *)callbackId
|
|
||||||
{
|
|
||||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
|
||||||
messageAsInt:code];
|
|
||||||
|
|
||||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Überprüft, ob der Drucker-Dienst verfügbar ist.
|
* Überprüft, ob der Drucker-Dienst verfügbar ist.
|
||||||
*/
|
*/
|
||||||
|
@ -46,27 +46,18 @@ Printer.prototype = {
|
|||||||
* Übergibt den HTML-Content an den Drucker-Dienst.
|
* Übergibt den HTML-Content an den Drucker-Dienst.
|
||||||
*
|
*
|
||||||
* @param {String} content HTML string or DOM node (if latter, innerHTML is used to get the contents)
|
* @param {String} content HTML string or DOM node (if latter, innerHTML is used to get the contents)
|
||||||
* @param {Function?} callback callback function called if print is completed. {success: bool, available: bool, error: reason}
|
|
||||||
* @param {Object?} scope callback scope (default: window)
|
|
||||||
* @param {Object?} options platform specific options
|
* @param {Object?} options platform specific options
|
||||||
*/
|
*/
|
||||||
print: function (content, callback, scope, options) {
|
print: function (content, options) {
|
||||||
var page = content.innerHTML || content,
|
var page = content.innerHTML || content,
|
||||||
options = options || {},
|
options = options || {};
|
||||||
callbackFn;
|
|
||||||
|
|
||||||
if (typeof page != 'string') {
|
if (typeof page != 'string') {
|
||||||
console.log('Print function requires an HTML string. Not an object');
|
console.log('Print function requires an HTML string. Not an object');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof callback == 'function'){
|
cordova.exec(null, null, 'Printer', 'print', [page, options]);
|
||||||
callbackFn = function () {
|
|
||||||
callback.apply(scope || window, arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cordova.exec(callbackFn, null, 'Printer', 'print', [page, options]);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user