Fix isServiceAvailable issue (solves #11)

This commit is contained in:
Sebastián Katzer 2014-07-13 11:26:58 +02:00
parent 02e39320d5
commit 03b70956ba

View File

@ -36,20 +36,8 @@
@end @end
@interface APPPrinter ()
// Getter property for the `isPrintingAvailable` method
@property (readonly, getter=isPrintingAvailable) BOOL isPrintingAvailable;
// Getter property for the `printController` method
@property (readonly, getter=printController) UIPrintInteractionController* printController;
@end
@implementation APPPrinter @implementation APPPrinter
@synthesize isPrintingAvailable, printController;
/* /*
* Checks if the printing service is available. * Checks if the printing service is available.
* *
@ -59,9 +47,10 @@
- (void) isServiceAvailable:(CDVInvokedUrlCommand*)command - (void) isServiceAvailable:(CDVInvokedUrlCommand*)command
{ {
CDVPluginResult* pluginResult; CDVPluginResult* pluginResult;
BOOL isAvailable = [self isPrintingAvailable];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsBool:isPrintingAvailable]; messageAsBool:isAvailable];
[self.commandDelegate sendPluginResult:pluginResult [self.commandDelegate sendPluginResult:pluginResult
callbackId:command.callbackId]; callbackId:command.callbackId];
@ -75,15 +64,14 @@
*/ */
- (void) print:(CDVInvokedUrlCommand*)command - (void) print:(CDVInvokedUrlCommand*)command
{ {
if (!self.isPrintingAvailable) if (!self.isPrintingAvailable) {
{
return; return;
} }
NSArray* arguments = [command arguments]; NSArray* arguments = [command arguments];
NSString* content = [arguments objectAtIndex:0]; NSString* content = [arguments objectAtIndex:0];
UIPrintInteractionController* controller = printController; UIPrintInteractionController* controller = [self printController];
[self adjustSettingsForPrintController:controller]; [self adjustSettingsForPrintController:controller];
[self loadContent:content intoPrintController:controller]; [self loadContent:content intoPrintController:controller];
@ -174,11 +162,12 @@
{ {
Class controllerCls = NSClassFromString(@"UIPrintInteractionController"); Class controllerCls = NSClassFromString(@"UIPrintInteractionController");
if (!controllerCls){ if (!controllerCls) {
return NO; return NO;
} }
return printController && [UIPrintInteractionController isPrintingAvailable]; return [self printController] && [UIPrintInteractionController
isPrintingAvailable];
} }
@end @end