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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2013 appPlant UG
|
Copyright 2013 appPlant UG
|
||||||
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
or more contributor license agreements. See the NOTICE file
|
or more contributor license agreements. See the NOTICE file
|
||||||
distributed with this work for additional information
|
distributed with this work for additional information
|
||||||
regarding copyright ownership. The ASF licenses this file
|
regarding copyright ownership. The ASF licenses this file
|
||||||
to you under the Apache License, Version 2.0 (the
|
to you under the Apache License, Version 2.0 (the
|
||||||
"License"); you may not use this file except in compliance
|
"License"); you may not use this file except in compliance
|
||||||
with the License. You may obtain a copy of the License at
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing,
|
Unless required by applicable law or agreed to in writing,
|
||||||
software distributed under the License is distributed on an
|
software distributed under the License is distributed on an
|
||||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
KIND, either express or implied. See the License for the
|
KIND, either express or implied. See the License for the
|
||||||
specific language governing permissions and limitations
|
specific language governing permissions and limitations
|
||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import <Cordova/CDVPlugin.h>
|
#import <Cordova/CDVPlugin.h>
|
||||||
|
@ -1,41 +1,36 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2013 appPlant UG
|
Copyright 2013 appPlant UG
|
||||||
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
or more contributor license agreements. See the NOTICE file
|
or more contributor license agreements. See the NOTICE file
|
||||||
distributed with this work for additional information
|
distributed with this work for additional information
|
||||||
regarding copyright ownership. The ASF licenses this file
|
regarding copyright ownership. The ASF licenses this file
|
||||||
to you under the Apache License, Version 2.0 (the
|
to you under the Apache License, Version 2.0 (the
|
||||||
"License"); you may not use this file except in compliance
|
"License"); you may not use this file except in compliance
|
||||||
with the License. You may obtain a copy of the License at
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing,
|
Unless required by applicable law or agreed to in writing,
|
||||||
software distributed under the License is distributed on an
|
software distributed under the License is distributed on an
|
||||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
KIND, either express or implied. See the License for the
|
KIND, either express or implied. See the License for the
|
||||||
specific language governing permissions and limitations
|
specific language governing permissions and limitations
|
||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#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
|
||||||
- (UIPrintInteractionController *) getPrintController;
|
- (UIPrintInteractionController*) getPrintController;
|
||||||
// Stellt die Eigenschaften des Druckers ein.
|
// Stellt die Eigenschaften des Druckers ein.
|
||||||
- (UIPrintInteractionController *) adjustSettingsForPrintController:(UIPrintInteractionController *)controller;
|
- (UIPrintInteractionController*) adjustSettingsForPrintController:(UIPrintInteractionController*)controller;
|
||||||
// Lädt den zu druckenden Content in ein WebView, welcher vom Drucker ausgedruckt werden soll.
|
// Lädt den zu druckenden Content in ein WebView, welcher vom Drucker ausgedruckt werden soll.
|
||||||
- (void) loadContent:(NSString *)content intoPrintController:(UIPrintInteractionController *)controller;
|
- (void) loadContent:(NSString*)content intoPrintController:(UIPrintInteractionController*)controller;
|
||||||
// Ruft den Callback auf und informiert diesen über den das Ergebnis des Druckvorgangs.
|
// Ruft den Callback auf und informiert diesen über den das Ergebnis des Druckvorgangs.
|
||||||
- (void) informAboutResult:(int)code callbackId:(NSString *)callbackId;
|
- (void) informAboutResult:(int)code callbackId:(NSString*)callbackId;
|
||||||
// Überprüft, ob der Drucker-Dienst verfügbar ist
|
// Überprüft, ob der Drucker-Dienst verfügbar ist
|
||||||
- (BOOL) isPrintServiceAvailable;
|
- (BOOL) isPrintServiceAvailable;
|
||||||
|
|
||||||
@ -47,7 +42,7 @@
|
|||||||
/*
|
/*
|
||||||
* Is printing available.
|
* Is printing available.
|
||||||
*/
|
*/
|
||||||
- (void) isServiceAvailable:(CDVInvokedUrlCommand *)command
|
- (void) isServiceAvailable:(CDVInvokedUrlCommand*)command
|
||||||
{
|
{
|
||||||
CDVPluginResult* pluginResult;
|
CDVPluginResult* pluginResult;
|
||||||
|
|
||||||
@ -61,11 +56,10 @@
|
|||||||
* Öffnet den Drucker-Kontroller zur Auswahl des Druckers.
|
* Öffnet den Drucker-Kontroller zur Auswahl des Druckers.
|
||||||
* Callback gibt Meta-Informationen an.
|
* Callback gibt Meta-Informationen an.
|
||||||
*/
|
*/
|
||||||
- (void) print:(CDVInvokedUrlCommand *)command
|
- (void) print:(CDVInvokedUrlCommand*)command
|
||||||
{
|
{
|
||||||
if (![self isPrintServiceAvailable])
|
if (![self isPrintServiceAvailable])
|
||||||
{
|
{
|
||||||
[self informAboutResult:APP_PRINT_FAILED callbackId:command.callbackId];
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,20 +72,16 @@
|
|||||||
[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];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Erstellt den PrintController.
|
* Erstellt den PrintController.
|
||||||
*/
|
*/
|
||||||
- (UIPrintInteractionController *) getPrintController
|
- (UIPrintInteractionController*) getPrintController
|
||||||
{
|
{
|
||||||
return [UIPrintInteractionController sharedPrintController];
|
return [UIPrintInteractionController sharedPrintController];
|
||||||
}
|
}
|
||||||
@ -99,7 +89,7 @@
|
|||||||
/**
|
/**
|
||||||
* Stellt die Eigenschaften des Druckers ein.
|
* Stellt die Eigenschaften des Druckers ein.
|
||||||
*/
|
*/
|
||||||
- (UIPrintInteractionController *) adjustSettingsForPrintController:(UIPrintInteractionController *)controller
|
- (UIPrintInteractionController*) adjustSettingsForPrintController:(UIPrintInteractionController*)controller
|
||||||
{
|
{
|
||||||
UIPrintInfo* printInfo = [UIPrintInfo printInfo];
|
UIPrintInfo* printInfo = [UIPrintInfo printInfo];
|
||||||
printInfo.outputType = UIPrintInfoOutputGeneral;
|
printInfo.outputType = UIPrintInfoOutputGeneral;
|
||||||
@ -112,7 +102,7 @@
|
|||||||
/**
|
/**
|
||||||
* Lädt den zu druckenden Content in ein WebView, welcher vom Drucker ausgedruckt werden soll.
|
* Lädt den zu druckenden Content in ein WebView, welcher vom Drucker ausgedruckt werden soll.
|
||||||
*/
|
*/
|
||||||
- (void) loadContent:(NSString *)content intoPrintController:(UIPrintInteractionController *)controller
|
- (void) loadContent:(NSString*)content intoPrintController:(UIPrintInteractionController*)controller
|
||||||
{
|
{
|
||||||
// Set the base URL to be the www directory.
|
// Set the base URL to be the www directory.
|
||||||
NSString* wwwFilePath = [[NSBundle mainBundle] pathForResource:@"www" ofType:nil];
|
NSString* wwwFilePath = [[NSBundle mainBundle] pathForResource:@"www" ofType:nil];
|
||||||
@ -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.
|
||||||
*/
|
*/
|
||||||
|
@ -45,28 +45,19 @@ 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?} options platform specific options
|
||||||
* @param {Object?} scope callback scope (default: window)
|
|
||||||
* @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