Ionic Common Plugin TIPS

This article is not a detailed explanation of the plug-in, but only lists the various plug-ins used in the company’s online project and the pits encountered. If you want to learn more about a plug-in, it is recommended to check it out on its official github.

The installation method of the ionic plugin: ionic plugin add pluginName

The way I find the plugin: first ngcordova, then cordova official (cordova official is a bit pitted, please pay attention to your cordova Version, don’t find a plug-in that hasn’t changed for a long time.

Plugins are written in a variety of native codes, so it is recommended that ionic developers have time to look at the native ones, and if they encounter pits, they can change them by themselves.

cordova-plugin-app-version

App version plug-in, used to prompt app update.

How to use:

Get the version number: cordova.getAppVersion.getVersionNumber()

tips: iOS version check is not required, because the app will be required Remove this feature! ! !

cordova-plugin-console

You can understand by looking at the name, that is, the console of the js file allows you to see the console of js in the xcode or android studio console.

tips: debugging artifact.

cordova-plugin-geolocation

This plugin is very awkward. It calls the native api and makes the interface into the w3c standard. Simply put, your location-related code only needs to be written once, just Can run on both sides of the app and the browser.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log("navigator.geolocation works well");
}

deviceready needs to depend on the cordova-plugin-device plug-in.

tips:

  • iOS devices are very supportive, and the positioning effect is also good. Some Android devices cannot obtain positioning. If the positioning requirements are very high, it is best to combine it with the original one.

  • You must complete the positioning after starting deviceready as in the above example, otherwise there will be a problem of two prompts on iOS.

cordova-plugin-inappbrowser

This plug-in is required to open the webpage in the app. The usage is similar to geolocation, it is compatible, just use window.open directly.

tips: In ionic, there will be problems with the a tag tel when dialing out. It needs to be written like this: in the click event window.open(“tel:” + 800xxxxxxx, “_system”);

< h4>cordova-plugin-splashscreen

The screen that enters the app is the plug-in.

tips: Ionic provides a picture workflow of ionic resource, that is, he will automatically generate splash pictures of various sizes. But it should be noted that you need to add the complete in the xml.config, otherwise there will be some models with pictures, and some models still have the cordova logo.

cordova-plugin-statusbar

The status bar plug-in, supports developers to define the status bar. You can refer to the readme for usage, a simple and practical plug-in.

ionic-plugin-keyboard

The keyboard plugin allows the input box in the app to pop up the keyboard. This is the ionic author’s own project, so I won’t say much.

tips: App initialize and define it.

cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);

cordova-plugin-x-toast

Native toast prompt, you should know that you use Android. Ionic can also do the prompt of native app. There are many usages, please refer to its github.

tips: under ngcordova, so use $cordovaToast directly.

Leave a Comment

Your email address will not be published.