跳过内容

开始

GitHub

您可以使用我们的 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-sim
bunx cap sync

导入

导入
import { Sim } from '@capgo/capacitor-sim';

API概述

API 简介

获取设备SIM卡的详细信息。 在双卡设备上,返回两个SIM卡的信息。 在Android上需要READ_PHONE_STATE权限。

获取设备SIM卡的详细信息。 在双卡设备上,返回两个SIM卡的信息。 在Android上需要READ_PHONE_STATE权限。

import { Sim } from '@capgo/capacitor-sim';
const { simCards } = await Sim.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 Sim.checkPermissions();
if (status.readSimCard === 'granted') {
console.log('Permission granted');
} else {
console.log('Permission not granted');
}

requestPermissions

请求权限

请求SIM卡信息权限

提示用户授予读取SIM卡数据的权限。 在Android中,请求READ_PHONE_STATE权限。 在iOS中,状态始终为已授权,无需提示。 在Web中,状态保持拒绝。

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

类型参考

类型参考

GetSimCardsResult

获取Sim卡结果

通过 . 返回的结果

export interface GetSimCardsResult {
simCards: SimCard[];
}

PermissionStatus

标题:权限状态

权限检查或请求的结果。

export interface PermissionStatus {
readSimCard: PermissionState;
}

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

如果您正在使用 开始使用 以计划仪表板和API操作,连接它 使用@capgo/capacitor-sim 为使用@capgo/capacitor-sim的本机功能 API概述 为API概述中的实现细节 介绍 为介绍中的实现细节 API密钥 为API密钥中的实现细节 设备 设备的实现细节。