콘텐츠로 건너뛰기

시작하기

  1. 플러그인 설치

    Terminal window
    npm i @capgo/capacitor-sim
  2. 플랫폼 동기화

    Terminal window
    npx cap sync
  • Android: android.permission.READ_PHONE_STATE (Android 13+ 에서는 READ_BASIC_PHONE_STATE) 권한이 부여되어야 합니다. Capacitor는 매니페스트 선언을 포함하지만, getSimCards를 호출하기 전에 권한을 요청해야 합니다.
  • iOS: 통신사 정보는 자동으로 제공되며, 플랫폼은 추가 권한을 요청하지 않습니다. iOS 16.4+ 의 OS 제한으로 인해 반환되는 데이터가 제한적임을 유의하세요.
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');
}
}
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,
});
});
  • 듀얼 SIM 기기: 반환된 배열을 반복합니다. 각 항목은 슬롯에 해당합니다. subscriptionId가 있으면 Android의 telephony API와 상호 작용하는 데 도움이 됩니다.
  • iOS 16.4+: Apple은 여러 통신사 속성을 편집합니다. 플레이스홀더 값(--, 65535)을 예상하고 UI에서 대체 방법을 계획하세요.
  • Web: 브라우저는 SIM 정보에 액세스할 수 없으므로 플러그인은 빈 데이터로 해결됩니다.