UIPrintInteractionController+APPPrinter category
Removes the need for special property to save the user setting
This commit is contained in:
parent
4046ab3473
commit
60444a8534
@ -75,6 +75,9 @@
|
|||||||
<header-file src="src/ios/APPPrinterPaper.h" />
|
<header-file src="src/ios/APPPrinterPaper.h" />
|
||||||
<source-file src="src/ios/APPPrinterPaper.m" />
|
<source-file src="src/ios/APPPrinterPaper.m" />
|
||||||
|
|
||||||
|
<header-file src="src/ios/UIPrintInteractionController+APPPrinter.h" />
|
||||||
|
<source-file src="src/ios/UIPrintInteractionController+APPPrinter.m" />
|
||||||
|
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
<!-- android -->
|
<!-- android -->
|
||||||
|
@ -21,13 +21,12 @@
|
|||||||
|
|
||||||
#import "APPPrinter.h"
|
#import "APPPrinter.h"
|
||||||
#import "APPPrinterItem.h"
|
#import "APPPrinterItem.h"
|
||||||
#import "APPPrinterInfo.h"
|
|
||||||
#import "APPPrinterPaper.h"
|
#import "APPPrinterPaper.h"
|
||||||
#import "APPPrinterLayout.h"
|
#import "APPPrinterLayout.h"
|
||||||
|
#import "UIPrintInteractionController+APPPrinter.h"
|
||||||
|
|
||||||
@interface APPPrinter ()
|
@interface APPPrinter ()
|
||||||
|
|
||||||
@property (retain) NSDictionary* settings;
|
|
||||||
@property (nonatomic) UIPrinter *previousPrinter;
|
@property (nonatomic) UIPrinter *previousPrinter;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@ -82,8 +81,6 @@
|
|||||||
NSMutableDictionary* settings = command.arguments[1];
|
NSMutableDictionary* settings = command.arguments[1];
|
||||||
settings[@"callbackId"] = command.callbackId;
|
settings[@"callbackId"] = command.callbackId;
|
||||||
|
|
||||||
self.settings = settings;
|
|
||||||
|
|
||||||
[self printContent:content withSettings:settings];
|
[self printContent:content withSettings:settings];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
@ -100,7 +97,7 @@
|
|||||||
choosePaper:(NSArray *)paperList
|
choosePaper:(NSArray *)paperList
|
||||||
{
|
{
|
||||||
APPPrinterPaper* paperSpec = [[APPPrinterPaper alloc]
|
APPPrinterPaper* paperSpec = [[APPPrinterPaper alloc]
|
||||||
initWithDictionary:_settings[@"paper"]];
|
initWithDictionary:ctrl.settings[@"paper"]];
|
||||||
|
|
||||||
return [paperSpec bestPaperFromArray:paperList];
|
return [paperSpec bestPaperFromArray:paperList];
|
||||||
}
|
}
|
||||||
@ -114,7 +111,7 @@
|
|||||||
cutLengthForPaper:(UIPrintPaper *)paper
|
cutLengthForPaper:(UIPrintPaper *)paper
|
||||||
{
|
{
|
||||||
APPPrinterPaper* paperSpec = [[APPPrinterPaper alloc]
|
APPPrinterPaper* paperSpec = [[APPPrinterPaper alloc]
|
||||||
initWithDictionary:_settings[@"paper"]];
|
initWithDictionary:ctrl.settings[@"paper"]];
|
||||||
|
|
||||||
return paperSpec.length || paper.paperSize.height;
|
return paperSpec.length || paper.paperSize.height;
|
||||||
}
|
}
|
||||||
@ -157,34 +154,6 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adjusts the settings for the print controller.
|
|
||||||
*
|
|
||||||
* @param view The view which content to print.
|
|
||||||
* @param settings The print job specs.
|
|
||||||
*
|
|
||||||
* @return A ready to use print controller instance.
|
|
||||||
*/
|
|
||||||
- (UIPrintInteractionController *) prepareControllerWithSettings:(NSDictionary *)settings
|
|
||||||
{
|
|
||||||
UIPrintInfo* printInfo = [APPPrinterInfo printInfoWithDictionary:settings];
|
|
||||||
NSDictionary* ui = settings[@"ui"];
|
|
||||||
|
|
||||||
UIPrintInteractionController* ctrl =
|
|
||||||
[UIPrintInteractionController sharedPrintController];
|
|
||||||
|
|
||||||
ctrl.printInfo = printInfo;
|
|
||||||
ctrl.delegate = self;
|
|
||||||
|
|
||||||
if (ui)
|
|
||||||
{
|
|
||||||
ctrl.showsNumberOfCopies = ![ui[@"hideNumberOfCopies"] boolValue];
|
|
||||||
ctrl.showsPaperSelectionForLoadedPapers = ![ui[@"hidePaperFormat"] boolValue];
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the content into the print controller.
|
* Loads the content into the print controller.
|
||||||
*
|
*
|
||||||
@ -199,7 +168,9 @@
|
|||||||
__block id item;
|
__block id item;
|
||||||
|
|
||||||
UIPrintInteractionController* ctrl =
|
UIPrintInteractionController* ctrl =
|
||||||
[self prepareControllerWithSettings:settings];
|
[UIPrintInteractionController sharedPrintControllerWithSettings:settings];
|
||||||
|
|
||||||
|
ctrl.delegate = self;
|
||||||
|
|
||||||
if ([self strIsNullOrEmpty:content])
|
if ([self strIsNullOrEmpty:content])
|
||||||
{
|
{
|
||||||
@ -444,4 +415,3 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
28
src/ios/UIPrintInteractionController+APPPrinter.h
Normal file
28
src/ios/UIPrintInteractionController+APPPrinter.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2013 appPlant GmbH
|
||||||
|
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@interface UIPrintInteractionController (APPPrinter)
|
||||||
|
|
||||||
|
+ (instancetype) sharedPrintControllerWithSettings:(NSDictionary *)settings;
|
||||||
|
|
||||||
|
@property (nonatomic, retain) NSDictionary *settings;
|
||||||
|
|
||||||
|
@end
|
70
src/ios/UIPrintInteractionController+APPPrinter.m
Normal file
70
src/ios/UIPrintInteractionController+APPPrinter.m
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2013 appPlant GmbH
|
||||||
|
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "APPPrinterInfo.h"
|
||||||
|
#include "UIPrintInteractionController+APPPrinter.h"
|
||||||
|
|
||||||
|
#import <objc/runtime.h>
|
||||||
|
|
||||||
|
@implementation UIPrintInteractionController (APPPrinter)
|
||||||
|
|
||||||
|
static char UIP_SETTINGS_KEY;
|
||||||
|
|
||||||
|
@dynamic settings;
|
||||||
|
|
||||||
|
#pragma mark -
|
||||||
|
#pragma mark Init
|
||||||
|
|
||||||
|
+ (instancetype) sharedPrintControllerWithSettings:(NSDictionary *)settings
|
||||||
|
{
|
||||||
|
NSDictionary* ui = settings[@"ui"];
|
||||||
|
|
||||||
|
UIPrintInteractionController* ctrl =
|
||||||
|
UIPrintInteractionController.sharedPrintController;
|
||||||
|
|
||||||
|
ctrl.printInfo = [APPPrinterInfo
|
||||||
|
printInfoWithDictionary:settings];
|
||||||
|
|
||||||
|
ctrl.settings = settings;
|
||||||
|
|
||||||
|
if (ui)
|
||||||
|
{
|
||||||
|
ctrl.showsNumberOfCopies = ![ui[@"hideNumberOfCopies"] boolValue];
|
||||||
|
ctrl.showsPaperSelectionForLoadedPapers = ![ui[@"hidePaperFormat"] boolValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark -
|
||||||
|
#pragma mark Private
|
||||||
|
|
||||||
|
- (void) setSettings:(NSDictionary *)settings
|
||||||
|
{
|
||||||
|
objc_setAssociatedObject(self, &UIP_SETTINGS_KEY, settings, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSDictionary *)settings
|
||||||
|
{
|
||||||
|
return objc_getAssociatedObject(self, &UIP_SETTINGS_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
Loading…
Reference in New Issue
Block a user