| name | capacitor |
| description | Capacitor cross-platform native runtime. Use for web to native. |
Capacitor
Capacitor by Ionic is a cross-platform native runtime that makes it easy to build web apps that run on iOS, Android, and the web as Progressive Web Apps (PWAs). It provides a bridge to native APIs.
When to Use
- Converting existing React/Angular/Vue web apps to mobile apps.
- Need specific native functionality (Camera, Haptics, Push) in a web app.
- Building plugins that need to work across iOS, Android, and Web consistent APIs.
Quick Start
npm install @capacitor/core @capacitor/cli
npx cap init MyMobileApp com.example.app
npm install @capacitor/android @capacitor/ios
npx cap add android
npx cap add ios
import { Geolocation } from "@capacitor/geolocation";
const printCurrentPosition = async () => {
const coordinates = await Geolocation.getCurrentPosition();
console.log("Current position:", coordinates);
};
Core Concepts
Native Bridge
Capacitor injects a native bridge into the WebView, allowing JavaScript to call Native Code (Java/Kotlin/Swift/Obj-C) asynchronously.