开始
复制一个包含安装步骤和本插件的完整 Markdown 指南的配置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-sim`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/sim/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
安装部分您可以使用我们的AI辅助设置来安装插件。使用以下命令将Capgo技能添加到您的AI工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-sim` plugin in my project.如果您更喜欢手动设置,请运行以下命令并按照以下平台特定的说明进行操作:
bun add @capgo/capacitor-simbunx cap sync导入
导入import { Sim } from '@capgo/capacitor-sim';API概述
API 介绍getSimCards
获取 SIM 卡从设备的 SIM 卡获取信息。
获取设备中安装的所有 SIM 卡的详细信息。 双 SIM 设备返回两个 SIM 卡的信息。 Android 需要 READ_PHONE_STATE 权限。
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}`);});checkPermissions
检查 SIM 卡权限检查应用是否有读取 SIM 卡数据的权限。 Android 检查 READ_PHONE_STATE 权限。 iOS 总是授予。 Web 总是拒绝。
复制到剪贴板
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');}__CAPGO_KEEP_0__
获取 SIM 卡
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();}类型参考
类型参考GetSimCardsResult
获取Sim卡结果Sim卡结果
export interface GetSimCardsResult { simCards: SimCard[];}PermissionStatus
权限状态权限检查或请求的结果
export interface PermissionStatus { readSimCard: PermissionState;}SimCard
Sim卡Sim卡描述
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;}真实数据来源
标题:真实数据来源本页面由插件的 src/definitions.ts重新同步时,公共API上游发生变化。
继续从 Getting Started
标题:继续从 Getting Started如果您正在使用 Getting Started 来规划仪表板和API操作,连接它到 使用@capgo/capacitor-sim 为在使用@capgo/capacitor-sim中native能力的 API概述 为 API 概述的实现细节 简介 为简介的实现细节 API 密钥 为 API 密钥的实现细节,和 设备 为设备的实现细节。