Passer au contenu

Getting Started

Ce contenu n'est pas encore disponible dans votre langue.

  1. Install the plugin

    Fenêtre de terminal
    npm i @capgo/capacitor-sim
  2. Sync platforms

    Fenêtre de terminal
    npx cap sync

Permissions

  • Android: Ensure android.permission.READ_PHONE_STATE (and on Android 13+, READ_BASIC_PHONE_STATE) is granted. Capacitor includes the manifest declarations, but you must request the permission before calling getSimCards.
  • iOS: Carrier information is available automatically; the platform does not prompt for additional permissions. Be mindful of the limited data returned on iOS 16.4+ due to OS restrictions.

Request runtime access (Android)

import { Sim } from '@capgo/capacitor-sim';
const status = await Sim.checkPermissions();
if (status.readSimCard !== 'granted') {
const updated = await Sim.requestPermissions();
if (updated.readSimCard !== 'granted') {
throw new Error('Telephony permission denied');
}
}

Read SIM cards

const { simCards } = await Sim.getSimCards();
simCards.forEach((card, index) => {
console.log(`Slot ${card.simSlotIndex ?? index}:`, {
carrier: card.carrierName,
mcc: card.mobileCountryCode,
mnc: card.mobileNetworkCode,
country: card.isoCountryCode,
subscriptionId: card.subscriptionId,
});
});

Platform considerations

  • Dual SIM devices: Iterate through the returned array; each entry corresponds to a slot. When present, subscriptionId helps you interact with Android’s telephony APIs.
  • iOS 16.4+: Apple redacts several carrier attributes. Expect placeholder values (--, 65535) and plan fallbacks in your UI.
  • Web: The plugin resolves with empty data because browsers cannot access SIM information.