Zum Inhalt springen

Getting Started

Terminalfenster
bun add @capgo/capacitor-sim
bunx cap sync
import { Sim } from '@capgo/capacitor-sim';

Ermittelt Informationen von den SIM-Karten des Geräts.

Beschafft Details über alle installierten SIM-Karten im Gerät. Bei Dual-SIM-Geräten werden Informationen für beide SIM-Karten zurückgegeben. Bereitstellung der READ_PHONE_STATE-Berechtigung auf Android erforderlich.

import { Sim } from '@capgo/capacitor-sim';
const { simCards } = await SimPlugin.getSimCards();
simCards.forEach((sim, index) => {
console.log(`SIM ${index + 1}:`);
console.log(` Carrier: ${sim.carrierName}`);
console.log(` Country: ${sim.isoCountryCode}`);
console.log(` MCC: ${sim.mobileCountryCode}`);
console.log(` MNC: ${sim.mobileNetworkCode}`);
});

Überprüfung der Berechtigung zur Zugriff auf SIM-Karteninformationen.

Überprüft, ob die App die Berechtigung zum Lesen von SIM-Karten-Daten besitzt. Bei Android wird die Berechtigung READ_PHONE_STATE überprüft. Bei iOS ist der Status immer gewährt. Bei Web ist der Status immer abgelehnt.

import { Sim } from '@capgo/capacitor-sim';
const status = await SimPlugin.checkPermissions();
if (status.readSimCard === 'granted') {
console.log('Permission granted');
} else {
console.log('Permission not granted');
}

Berechtigung zum Zugriff auf SIM-Karteninformationen anfordern.

Fordert den Benutzer auf, die Berechtigung zum Lesen von SIM-Karten-Daten zu gewähren. Bei Android wird die Berechtigung READ_PHONE_STATE angefordert. Bei iOS ist der Status immer gewährt, ohne dass der Benutzer aufgefordert wird. Bei Web bleibt der Status abgelehnt.

import { Sim } from '@capgo/capacitor-sim';
const status = await SimPlugin.requestPermissions();
if (status.readSimCard === 'granted') {
// Now you can call getSimCards()
const simCards = await SimPlugin.getSimCards();
}

Erfolgsmeldung von .

export interface GetSimCardsResult {
simCards: SimCard[];
}

Erfolgsmeldung einer Berechtigungsprüfung oder -anfrage.

export interface PermissionStatus {
readSimCard: PermissionState;
}

Eine SIM-Kartenbeschreibung.

export interface SimCard {
/**
* Android only: Phone number for this SIM slot, when available.
*
* @since 1.0.0
*/
number?: string;
/**
* Android only: Unique subscription identifier.
*
* @since 1.1.0
*/
subscriptionId?: string;
/**
* Android only: Physical SIM slot index for this subscription.
*
* @since 1.1.0
*/
simSlotIndex?: number;
/**
* iOS only: Indicates whether the carrier supports VoIP.
*
* @since 1.0.0
*/
allowsVOIP?: boolean;
/**
* Display name of the cellular service provider.
*
* On iOS 16.4+ the system may return placeholder values such as `--`.
* See https://github.com/jonz94/capacitor-sim/issues/8 for details.
*
* @since 1.0.0
*/
carrierName: string;
/**
* ISO 3166-1 alpha-2 country code of the service provider.
*
* On iOS 16.4+ the system may return an empty string or `--`.
* See https://github.com/jonz94/capacitor-sim/issues/8 for details.
*
* @since 1.0.0
*/
isoCountryCode: string;
/**
* Mobile Country Code (MCC) of the service provider.
*
* On iOS 16.4+ the system may return placeholder values such as `65535`.
* See https://github.com/jonz94/capacitor-sim/issues/8 for details.
*
* @since 1.0.0
*/
mobileCountryCode: string;
/**
* Mobile Network Code (MNC) of the service provider.
*
* On iOS 16.4+ the system may return placeholder values such as `65535`.
* See https://github.com/jonz94/capacitor-sim/issues/8 for details.
*
* @since 1.0.0
*/
mobileNetworkCode: string;
}

Diese Seite wird aus dem Plugin generiert. src/definitions.ts. Wiederholen Sie die Synchronisierung, wenn die öffentliche API sich im Hintergrund ändert.

Wenn Sie " Getting Started um das Dashboard und die API-Operationen zu planen, verbinden Sie es mit Mit @capgo/capacitor-sim für die native Fähigkeit in Mit @capgo/capacitor-sim, API-Übersicht für die Implementierungsdetails in API-Übersicht, Einführung für die Implementierungsdetails in Einführung, API Schlüssel für die Implementierungsdetails in API Schlüssel, und Geräte für die Implementierungsdetails in Geräte.