问题
I'm trying to implement AirPrint printing and need to instantiate UIPrintInteractionController
. However, I can't seem to get it to find the class. How can I access this UIKit class from NativeScript?
function findPrinter() {
var printController = UIPrintInteractionController.new();
console.log(printController);
}
exports.findPrinter = findPrinter;
回答1:
Use the following syntax for your case :
function findPrinter() {
var printController = UIPrintInteractionController;
console.log(printController.isPrintingAvailable());
}
exports.findPrinter = findPrinter;
Here are some more example for Objective-C to JS based on the {N} documenation
Objective-C code
NSMutableArray * array = [[NSMutableArray alloc] init];
Class buttonClass = [UIButton class];
UIButton * button = [[buttonClass alloc] init];
[array setObject: buttonClass atIndex: 0];
[array setObject: button atIndex: 1];
NativeScript code
var array = new NSMutableArray();
var buttonClass = UIButton;
var button = new buttonClass();
array.setObjectAtIndex(buttonClass, 0);
array.setObjectAdIndex(button, 1);
More details can be found at NativeScript documentation
来源:https://stackoverflow.com/questions/36780044/how-to-access-the-uiprintinteractioncontroller-class-with-nativescript