Ionic-native cordova error

I am trying to use Push notifications in an Ionic 2 ts project. I have followed the quick guide in this post to get webpack working:

Now when I try to call Push.init, it does so and then gives this warning message

Native: tried calling Push.init, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator

when I use ionic serve. Even when I uncomment the cordova.js script html tags I get this error. I understand that Push notifications haven’t been tested in Ionic 2 but I think this is related to something else since the error is about cordova. How can I get ionic-native to see cordova?

1 Like

Like the error message mentioned, you’re trying to use cordova but it is not available. This is because you’re trying to use a cordova plugin in your browser (ionic servce). To my recollection, cordova is not accessible when you’re working in a browser. You should deploy your app to your device/emulator, then the cordova plugins should work.

2 Likes

So if i use browser i can’t access to cordova plugins unless i open url in iOs safari?

1 Like

You’re building hybrid app using ionic, not web app. Cordova is there to provide interface/bridge for browser engine to interact with device native api, which include, Push. If you’re building a web app, you can’t access device push because normal browser don’t provide those interface. Like myself, I hardly ever touch browser for development. Instead, I build directly on device and use remote debugging to view any error.

1 Like

How do you do that? Do you have an ANT Task for that or any commands? Thanks in advance

How do you do what? Need context.

How do he builds directly on device and use remote debugging instead of working with the browser?

What such a workflow would look like? Might sound obvious but from a beginner’s point of view it’s hard to understand at first.

I work with the browser and use ionic serve and that’s it, for example, would love to know more. Unfortunately my professor is unable to answer most of the questions i have and youtube isn’t helping.

I’m working on my first real app and now i want to be able to open a picture full-screen, simple right? I added this https://ionicframework.com/docs/native/photo-viewer/

And i can’t see any difference, stuff isn’t working, and i’m getting this error:
Capture

What I do is use Chrome’s Developer Tools. It has a “remote devices” option that allows attaching to apps running on device. There are probably Ionic CLI ways of running it, but I just use ionic cordova build android and adb install.

Native plugins, with a few exceptions, won’t work in a browser at all, and I don’t think any of them work under ionic serve.

@rapropos Basically you build the app and then install it on your phone and test it manually, right? It’s the only way to test Cordova plugins?