javascriptnativescriptairprint

How to access the UIPrintInteractionController class with NativeScript


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;

Solution

  • 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