Ionic capacitor plugins

Ionic capacitor plugins DEFAULT

How to Build Your Own Capacitor Plugin for Ionic

How to Build Your Own Capacitor Plugin for Ionic

When you work with a framework like Capacitor, you should know how it works internally, and how you can overcome challenges even if there’s not a plugin out there for your needs.

That’s why we are going to create our very own Capacitor plugin today that works on both iOS, Android and with a little fallback for the web as well.

We are going to retrieve the native contacts of a phone (which of course doesn’t work very well on the browser) and write some Swift and Java code for the native platforms to handle everything efficient.

Creating the Capacitor Plugin

To get started with a new Capacitor plugin, you can simply call the generate command of the Capacitor CLI (install if you haven’t) which will ask for a bunch of details:

[email protected]/cli plugin:generate

You can answer the questions as you want, but if you want to follow the names in this tutorial, here’s what I used.

Afterwards you can dive into your new plugin and create a first build using the predefined NPM script. Let’s also check out what the plugin is actually made of:

  • Android: The native implementation of the plugin for Android
  • dist: The build output folder which is used on the web
  • ios: The native implementation of the plugin for iOS
  • src: The web implementation of your plugin and its interface

These are the most important folders of your plugin, so let’s start to tackle our plugin one by one.

Web Capacitor Plugin Code

First of all we need to define a new function on the interface of the plugin. There’s already one dummy function defined, and we will simply add another one inside the src/definition.ts:


We wanna have a function to retrieve contacts, and we can pass any value to this function and access it within the plugin implementation later.

For the web, the implementation is actually just a dummy fallback since there are no native contacts. But if your plugin has the ability to work on the web, this would be the place to implement the Typescript logic of it.

Continue by adding your new function and a super simple implementation to the src/web.ts:

  async echo(options:{value:string}):Promise<{value:string}>{
  async getContacts(filter:string):Promise<{results:any[]}>{
    console.log('filter: ',filter);

In here we can see the already existing function, and within the constructor we see the supported platforms. This actually means that the web code is only used on the web – it doesn’t mean your plugin won’t work on other platforms!

Only if you want to use the web implementation of your plugin on the other native platforms, you would add them to the array in here.

At this point we could already integrate the plugin in our app, but let’s stick to this project before we dive into the usage in the end.

iOS Capacitor Plugin Code

To edit your iOS implementation, I highly recommend to use the native tooling, which means you should open the ios/Plugin.xcworkspace with Xcode.

This will give you the right syntax highlighting and the best available code completion to write your plugin.

Now I don’t really know Swift anymore after years, but with some general coding knowledge it’s quite easy to find tutorials on the native implementation of features, that you can easily adapt and integrate into the Capacitor shell and format that we need to follow!

First of all, we need to register our function within the ios/Plugin/Plugin.m, following the same structure like the existing dummy function:

#import <Foundation/Foundation.h>
#import <Capacitor/Capacitor.h>
// Define the plugin using the CAP_PLUGIN Macro, and
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.

Next step is to create the function we just registered and add the Swift code.

As said before, I made this solution work based on some Swift tutorials and looking up Stack overflow answers, so most likely it’s not the best way, but it works!

Within the Swift file of our plugin we already see the dummy function, which get’s one argument that contains all the information about the plugin call. From this object you could extract all the information you initially passed to the plugin.

In our case, we could extract the filter value and use it in the native code, but I’ll leave the filtering logic up to you as a little task (read: I was too lazy to add it in the end).

Afterwards follows the native code to retrieve the device contacts, add them to an array and finally use our call variable to report a success back to our calling code and pass the results along.

If we fail, we can also use which would then give us an error of our Promise inside Javascript.

Go ahead and change the ios/Plugin/Plugin.swift to this now:

    @objc func echo(_call:CAPPluginCall){
        let value=call.getString("value")??""
    @objc func getContacts(_call:CAPPluginCall){
        let value=call.getString("filter")??""
        // You could filter based on the value passed to the function!
        let contactStore=CNContactStore()
        let keys=[
        let request=CNContactFetchRequest(keysToFetch:keys as![CNKeyDescriptor])
            iflet error=error{
                print("failed to request access",error)
                call.reject("access denied")
                   print("unable to fetch contacts")
                   call.reject("Unable to fetch contacts")
                print("access denied")
                call.reject("access denied")

We also added a new import and again, I didn’t know a thing about this Swift implementation but still made it work, so you can do the same for any native function that you want to create a plugin for!

Android Capacitor Plugin Code

The Android code took me a bit longer since I didn’t (and still don’t) understand the retrieving logic correctly but it mostly works as well now.

Once again, I highly recommend opening your Android folder with Android Studio to build your plugin. Native tooling, code completion, much better than your usual familiar IDE.

For Android things got a bit more challenging since the plugin needs to ask for permission first, which blows the code up a bit.

In the snippet below you can see that we have the same initial function that will be called, which us annotated with to mark it for Capacitor.

But we also define a unique code for our permission dialog and add it to the annotation of our class, because the flow for permissions looks like this:

  1. Use to save the information of our plugin call
  2. Trigger the permission dialog by using or other functions to start the dialog, and pass the unique ID to it
  3. Handle the result of the dialog within the and check if you can load the plugin data using
  4. Compare the with the static value we defined to know for which permission dialog the result came in
  5. Finally if everything is fine, call the actual logic of your plugin, which in this case is the

It’s a bit more tricky, but a good example of how to build more complex Capacitor plugins – and if you think about it, the flow is actually quite nice, a bit like a callback in Javascript.

Now go ahead and change your android/src/main/java/com/devdactic/contacts/ (you might have a different package name though) to:

import android.content.ContentResolver;
import android.database.Cursor;
import android.provider.ContactsContract;
import com.getcapacitor.JSObject;
import com.getcapacitor.NativePlugin;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import org.json.JSONArray;
import java.util.ArrayList;
import java.util.HashMap;
    protectedstaticfinalintREQUEST_CONTACTS=12345;// Unique request code
    publicvoidgetContacts(PluginCall call){
        // Filter based on the value if want
        PluginCall savedCall=getSavedCall();
            Log.d("Test","No stored plugin call for permissions request result");
                Log.d("Test","User denied permission");
            // We got the permission!
    voidloadContacts(PluginCall call){
        ContentResolver cr=this.getContext().getContentResolver();
        Cursor cur=cr.query(ContactsContract.Contacts.CONTENT_URI,
                Map<String,String>map=  newHashMap<String,String>();
                    Cursor pCur=cr.query(
                            ContactsContract.CommonDataKinds.Phone.CONTACT_ID+" = ?",
                    Log.i("phoneNUmber","The phone number is "+contactNumber);
        JSONArray jsonArray=newJSONArray(contactList);
        JSObject ret=newJSObject();

In the end we return again an array of the same type like we did before inside the web and iOS implementation. Make sure your plugin doesn’t return a different format on different platforms. You want to use a unified API in your Ionic app, and therefore the result on all platforms should have the same interface!

After you are done with everything, you can run a final and we are done with the Capacitor plugin!

Using Your Capacitor Plugin with Ionic

For the integration, let’s quickly start a blank Ionic app with Capacitor support. The official guide recommends to link your local plugin now, which actually didn’t work well for me. Instead, I simply passed the local path to the plugin to the install command, so make sure you put in the right path to your Capacitor plugin in this step!

ionic start devdacticPlugin blank--type=angular--capacitor
# Build app and add native platforms

Once the plugin is installed, you should see an entry like this in your package.json:


Of course this won’t work well with your colleagues (unless they also have the plugin and Ionic app next to each other), but for testing and building the plugin this should be perfectly fine, and we’ll see another benefit of this in the end as well.

Android Plugin Integration

The integration of Capacitor plugins always comes with some steps, you can see this for basically every community plugin.

In our case we first need to add the permission that our plugin needs inside the android/app/src/main/AndroidManifest.xml at the bottom where we can already see a bunch of other permissions:

<uses-permission android:name="android.permission.READ_CONTACTS"/>

To use the Capacitor plugin on Android we also need to register it inside the main activity, which we can do by loading the package (watch out for your package id in that path for both plugin and your app!) and calling the function inside the initialise within our android/app/src/main/java/io/ionic/starter/

import com.devdactic.contacts.ContactsPlugin;
import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import com.getcapacitor.Plugin;
import java.util.ArrayList;
  publicvoidonCreate(Bundle savedInstanceState){
    // Initializes the Bridge
      // Additional plugins you've installed go here

This step is (afaik) always necessary for Android plugins.

iOS Plugin Integration

For iOS we also need to add a permission to read the contacts, which we can do inside the ios/App/App/Info.plist:

<string>We need your data</string>

You can do this directly from code or within Xcode by adding a row and searching for “Privacy”, which will prompt you with a bunch of permissions that you could add.

Capacitor Plugin Usage

Now we can finally integrate our own plugin. Since the plugin is registered within Capacitor we can destructure the object and extract the name of our plugin from there. This name is what you can find in the interface of your plugin!

It’s important to also add the import line using the name of the plugin (as specified in the package.json) because this will actually trigger the web registration of your plugin – otherwise the web part of it won’t work!

Once everything is added, we can simply use the plugin like any other plugin and use our created function to fetch the contacts, so open the home/ and add this:

  async loadContacts(){    
    this.contacts=(await ContactsPlugin.getContacts('somefilter')).results;
    console.log('my contacts: ',this.contacts);    

To wrap things up, simply add a little iteration over our contacts so we can display our result within the home/

  <ion-toolbar color="primary">
      Devdactic Capacitor Plugin
  <ion-button expand="full"(click)="loadContacts()">
    Load Contacts
    <ion-item *ngFor="let c of contacts">

Now you can test your new plugin on the browser, and also within the native platforms of your Ionic app!

Capacitor Plugin Development Workflow

For this tutorial we have tackled the Capacitor plugin first, and then integrated it within our Ionic project. And if you know a bit about native development and can make it work immediately, that’s fine.

But usually, there’s another way to test and debug your plugin, which I actually also used to develop the code for this tutorial:

You create the plugin, integrate it with the local installation and then you continue to work on your plugin right from your Ionic app!

That means, you would run to open Xcode, and you can work on your plugin directly from there.

Hit save, run the app again on your Simulator or device and you can use native debugging with breakpoints to work on your plugin from there.

The same is true for Android as well, so after running from your Ionic app, edit the plugin right in there:

This development speed beats everything I’ve experienced with Cordova, and given the native tools, this is really the best way to develop and debug your plugin at the same time.

Because the plugin is basically a link to the files right inside your plugin folder, all the changes you make here are also directly saved inside the plugin folder – you are basically working on the same files!


If you can’t find the right Capacitor community plugin for your needs, simply go ahead and create your own!

We’ve seen that it’s easier than ever today, given the boilerplate of the generate command and the native debugging and development environment. And when you are done with the plugin, you can run to make it available to everyone so we can all install it simply using npm!

You can also find a video version of this tutorial below.

Get the free 7 day Ionic 4 Crash Course to learn how to:

  • Get started with Ionic
  • Build a Tab Bar navigation
  • Make HTTP calls to a REST API
  • Store Data inside your app
  • Use Cordova plugins
  • Style your Ionic app

The course is free, so there's nothing you can lose!

Success! Now check your email to confirm your subscription.


Capacitor Plugin APIs

Capacitor includes a number of native plugin APIs that are available to all Capacitor apps. These can be thought of as Capacitor “core plugins,” and they make it easy to access commonly needed functionality on each platform.

For those coming from Cordova, the core Capacitor plugins cover much of the core Cordova plugins, and also include some new ones.

See the Plugins list on the left menu for the full list of available plugins.

API Usage

To use a Capacitor plugin, follow these steps:

1) Import the object. It represents the registry of all Capacitor plugins.

2) Get a plugin from the Plugin Registry ( object).

3) Use the plugin API:

A common mistake is to import a plugin directly, then use the plugin API immediately, resulting in the web implementation being used:

By using the plugins from the plugin registry ( object), the native implementation of the plugin is used (if available), with fallback to the web version.

Angular Notes

Capacitor plugin event listeners run outside of Angular’s execution context. Contain handler logic within an block to ensure Angular’s change detection is triggered:

  1. Reason lite rack
  2. Wooden tags large
  3. Perf script
  4. 350z seibon

Announcing Capacitor 3.0

Capacitor 3 Image

Today I’m thrilled to announce the 3.0 release of Capacitor, Ionic’s native runtime that makes it easy to build web apps that run on iOS, Android, Desktop, and on the web as Progressive Web Apps — all powered by a single codebase.

Capacitor connects the web to native, enabling the best of both worlds by providing the tooling and runtime that make it possible to take any modern web app and deploy it natively to all the platforms you care about.

With the release of Capacitor 3.0, we’re unlocking a new approach to building native apps with web technology — a category we’re calling Web Native apps.

In fact, Capacitor is quickly becoming the de facto standard for web developers building for mobile. It’s installed half a million times per month and growing rapidly, with thousands of new apps kicked off every week. It was also rated #1 in satisfaction among mobile development tools on the latest State of JS survey.

With the release of Capacitor 3.0, we’re planting a stake in the ground: Capacitor is now the standard for web developers building mobile apps. We’re firmly committed to making mobile development just as good as web development, and that’s exactly what Capacitor enables. Whether you have an existing web project or are curious about starting a new mobile project, we hope you’ll check out Capacitor.

Now, on to Capacitor 3.0’s major updates, which include improved performance, enhanced developer experience, and greater community involvement.


Performance: everyone’s favorite topic! As you know, when it comes to building world-class apps, especially those that run across multiple platforms, great performance is a must. The Ionic and Capacitor teams are always laser-focused on maintaining great performance and developer experience, and Capacitor 3.0 is no exception.

We took a fresh look at Capacitor to find creative ways that we could further improve performance, including reduced app bundle size and improved app launch time.

Official Plugins Separated from Capacitor Core

First, to reduce app bundle size, the official Capacitor plugins have been separated from Capacitor Core.

This is a departure from previous versions of Capacitor. Until now, the 20+ official Capacitor plugins, which span everything from camera, to geolocation, filesystem and push notification support, were bundled together with Capacitor Core, the native runtime code that powers the ability to deploy your web app as a native app. This made getting started with Capacitor really easy, providing access to common native features out-of-the-box.

However, since all plugins were bundled with Core, your app would contain code for all available native features — even those you weren’t using. Additionally, plugin permissions were automatically configured in Capacitor-powered iOS and Android native projects. This meant it wasn’t always apparent why native features were included if they weren’t being used. This prompted questions like, “Why does my app ask for permission to use the camera if I’m not using that feature?”

With Capacitor 3, you can use only the features you need. Simply import the exact plugin you’d like to use and you’re on your way. Most of the APIs have stayed the same too, so you can upgrade in only a few steps. View complete details here, but in practice, here’s what it looks like:

Lazy Load Web Plugins

Finally, plugins are now lazy loaded based on the platform the app is running on. For example, an app running on Electron will only load Electron-based plugins, and will not load plugins for other platforms that aren’t required, such as iOS or Android. This helps keep bundle sizes down, and ensures platform-specific code is not accidentally executed on the wrong platform.

Enhanced Developer Experience

Capacitor 3 also adds a number of improvements to Capacitor’s developer experience, starting with the native mobile tooling:

New CLI “run” Command

Capacitor’s tooling has received a bunch of improvements too. By popular demand from the community, we’ve created a new “Run” command that eliminates unnecessary context switching from code editor to native IDEs. It copies web assets into native projects, programmatically invokes a native debug build, then deploys the app to Android and iOS (physical or virtual) devices. Not only can you build and deploy faster, it frees up your computer’s resources since you no longer need to have the native IDEs open while developing and testing apps.

TypeScript Configuration Files

The Capacitor configuration file, used to configure and set high-level options for Capacitor tooling as well as the native mobile apps in JSON format, can now be written in TypeScript. This means you can configure Capacitor in a type-safe manner (including autocomplete and inline documentation). One exciting benefit is the ability to specify different configurations based on the development environment (such as development, QA, and production), as well as leveraging environment variables to customize the app experience.

Updated Permissions API

In order to access certain native features, such as geolocation or camera access, apps need to request permission from users first. This is accomplished by a plugin permissions API, which has been reimagined in Capacitor 3.0 to offer a standardized mechanism for controlling plugin permissions.

Prior to 3.0, permission prompts were presented when the user first interacted with a feature. For example, when first accessing camera functionality, the user would be prompted to grant permission to the app to use the camera feature. Now, Capacitor developers have the ability to prompt permission requests at any time. For example, the user may be prompted to grant access when the app is first installed. This provides more flexibility in the user experience by allowing the developer to decide when and how permission prompts are presented to the user, rather than when the feature requiring permissions is first accessed.

Community Investment

At Ionic, we’ve always believed in the power of open source and the open source community. With the launch of Capacitor 3.0, we’ve taken a fresh look at how we can improve our investment in our wonderful community through a new GitHub org, public milestones, and improved community support.

Capacitor Community GitHub Organization

Almost one year ago, we rolled out the Capacitor Community GitHub organization. It hosts plugins, tools, and other projects — all contributed and maintained by the community.

Today, the org hosts many popular plugins and tools, and more are being added all the time. If there’s a plugin you’d like to see built, add a request to the Proposals repository. We’ve had a number of great plugins make it in so far, including Bluetooth Low Energy and a barcode scanner.

Speaking of plugins, we’ve also created a new documentation generation tool, which standardizes how Capacitor plugins are documented on both the GitHub and npm landing pages.

That’s not all. Capacitor now supports community-maintained platforms. The first platform is Electron; huge shout out to Mike Summerfeldt for leading this effort! Through a new standardized model and development template, other platforms can be added by the community in the future.

Between the 20+ official Capacitor plugins and tons of community plugins, you can be confident you’ll find the native features you need to build great apps.

Increased Transparency

Not only is our code open source, but our work is, too. Recently, we’ve increased Capacitor’s project transparency with public milestones and project planning all on GitHub.

Community Forum

Since Ionic’s early days, we’ve centered our focus on open source and community building. We’re proud of how welcoming and inclusive our community is. That said, we’re always looking for ways to do more, so recently we’ve taken steps to increase our community presence even further on the Ionic Forum. Our goal is to ensure you can build great apps by getting your questions answered by the Ionic team and the broader community, and in general, feel confident investing in Capacitor and its ecosystem. See you online!

Capacitor 3 Migration

Excited to try out Capacitor 3.0’s great new features? We’ve taken steps to ensure that migration is as smooth as possible. Check out the migration guide, featuring the required tooling to run Capacitor 3.0 apps as well as steps to update official plugins and your iOS and Android projects.

If you’re a plugin author looking to upgrade your plugins to Capacitor 3.0, see the Capacitor plugin upgrade guide. It documents the migration steps for iOS, Android, the web, and adopting the new Permissions API.

Introducing Ionic Portals: Power Up Existing Native Apps with Capacitor

As a bonus, we’re excited to announce Ionic Portals, a supercharged Web View control for safely embedding rich web experiences into existing native apps built on top of Capacitor.

With Portals, native and web teams can collaborate to bring existing web experiences and micro-apps to native, without getting in the way of the existing native app roadmap. Portals supplies a native API with the ability to extend the Web View with custom native functionality, providing robust web-to-native capabilities to embedded web apps.

To learn more about Portals, watch a demo, and join the waitlist, visit the Portals announcement page.

What’s next for Capacitor?

With v3 out, we’re starting to think about what’s next for Capacitor. When we created Capacitor, one of our goals was to make it the most stable native runtime on the market, so stability is an ongoing focus for us. We want Capacitor to Just Work and always be a joy to use. That work is never-ending and is a major focus for us.

Beyond stability, we are investigating a number of features that we think will be much appreciated by the community. One of which is making testing easier. We know that testing Web Native apps today can be difficult, since most solutions focus on testing either the web side or the native side but rarely both together. We think this is an area we can improve and are exploring options for doing that. We’re also building out Ionic Portals to bring Capacitor to existing native apps in a way that native developers will love.

Once we catch our breath after the v3 launch we’ll share more insight into Capacitor’s roadmap, so stay tuned for that. Your feedback on areas you want to see us improve is always appreciated and helps us figure out where to focus.

Build Apps with Capacitor 3.0 Now

More developers than ever are migrating to Capacitor, or joining us for their very first app. We hope you’ll check it out for your next cross-platform project. You can drop Capacitor into any existing web app, framework, or library, including React, Svelte, Vue, Tailwind (or your preferred Web Framework) projects.

Start building awesome Capacitor 3 apps now.

How to create a Capacitor plugin for iOS/Android

He is handsome. Laughter rang out in the car. Stas continued to torment my ass, he always finished for a long time when he was drunk. When he finally poured his sperm into my ass, I almost ran out of the car under the laughter of my old lovers, straightening my dress on the go.

Capacitor plugins ionic

Often she, her husband and son came to visit us, or we went to them on holidays. But what happened next, I never expected. Yes, she interested me in an intimate sense. I saw her in swimsuits, her underwear.

Capacitor + Nx = Cross Platform Plugin Development - Brandon Roberts - Ioniconf 2021

The last time I had anal sex was two years ago. Dima "Well, youre tight, well fucking work it out right now. " It began to accelerate. The pain was wild. But he did not stop, did not let me get used to the new sensations, but only continued to furiously move in me with his big long.

Similar news:

Her seductive body, pressed against my hairy torso. More kisses, more caresses, the first, such a sweet penetration is about to happen, the harbinger of a flight to heaven. Bummer. Stop, DD.

1329 1330 1331 1332 1333