Can't include Printer from ionic-native


#1

Hi,
anyone knows why I can not import Printer from ionic-native?

import {Printer} from ‘ionic-native’;

Console error:

Error TS2305: Module ‘"/Users/myuser/Documents/test-ionic-app/node_modules/ionic-native/dist/index"’ has no exported member ‘Printer’.

There is my system information:

Cordova CLI: 6.2.0
Gulp version:  CLI version 1.2.1
Gulp local:   Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.10
Ionic CLI Version: 2.0.0-beta.32
Ionic App Lib Version: 2.0.0-beta.18
ios-deploy version: 1.8.6 
ios-sim version: 5.0.8 
OS: Mac OS X El Capitan
Node Version: v5.11.1
Xcode version: Xcode 7.3 Build version 7D175 

Thanks in advance.


#2

According to the ionic-native’s changelog file, printer plugin was added on version 1.3.1.
I was using ionic-native version 1.2.4.

After update ionic native to the latest available version, the error from console disapears but the plugin still not printing anything.

I’m using this code:

Printer.print('<h1>HELLO WORLD</h1>')
    .then(
        () => console.log('success Print'),
        (err) => console.log('error Print', err)
     );

xCode prints me this error:

2016-06-30 16:04:56.317 myapp[267:58628] -[NSNull objectForKey:]: unrecognized selector sent to instance 0x392cb9e0
2016-06-30 16:04:56.318 myapp[267:58628] *** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: -[NSNull objectForKey:]: unrecognized selector sent to instance 0x392cb9e0

Help, please.


#3

Is this on a simulator or a real device?


#4

Is on a real device but, finally, I could fix it:

ionic plugin rm de.appplant.cordova.plugin.printer
ionic plugin add https://github.com/katzer/cordova-plugin-printer.git

After reinstall printer plugin I applied this pull request:

And now, printer works as expected.

Thanks for your interest @mhartington.