简体   繁体   中英

How to debug a cordova plugin with your phone?

I use Weinre to get a console from my phone. But on Javascript errors with plugins (contacts, geolocalisation etc...) I get nothing....

I don't know how to push on the console every javascript errors.

How to easily debug your javascript which use a plugin present only on your device ?

Thank you.

You can use the Console Plugin to debug your code in iOS, android, windows phone, etc.

Install the plugin using: $ cordova plugin add org.apache.cordova.console

Then its as simple as using console.log(...); in your javascript files.

If you want to log your geolocation you can do:

var onSuccess = function(position) {
    console.log(position.coords.latitude);
    console.log(position.coords.longitude);
};

var onError = function(err) {
    console.log(error.code);
    console.log(error.message);
};

navigator.geolocation.getCurrentPosition(onSuccess, onError);

Then, when you build your app, and emulate, look for this log file in your project:

.../platforms/ios/cordova/console.log

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM