jonz94 / capacitor-sim Goto Github PK
View Code? Open in Web Editor NEW⚡️ Capacitor plugin to get information from device's sim cards.
Home Page: https://www.npmjs.com/package/@jonz94/capacitor-sim
License: BSD Zero Clause License
⚡️ Capacitor plugin to get information from device's sim cards.
Home Page: https://www.npmjs.com/package/@jonz94/capacitor-sim
License: BSD Zero Clause License
Hey i want to update my phone number component when I'm actaually getting the value of the phone number. I'm using next.js
Also the country code overrides the phonenumber value completely
"use client";
import { useState, useEffect } from "react";
import PhoneInput from "react-phone-input-2";
import "react-phone-input-2/lib/style.css";
import { GetSimCardsResult, Sim, SimCard } from "@jonz94/capacitor-sim";
import { Capacitor } from "@capacitor/core";
const simIsAvailable = Capacitor.isPluginAvailable('Sim');
export default function PhoneInputBox() {
const [phone, setPhone] = useState("");
const [country, setCountry] = useState("us");
if (simIsAvailable) {
useEffect(() => {
let hasPermission = true;
Sim.requestPermissions().then((permStatus) => {
hasPermission = permStatus.readSimCard === "granted";
})
if (hasPermission) {
Sim.getSimCards().then(async (result: GetSimCardsResult) => {
const simCard: SimCard = await result.simCards[0];
setPhone(simCard.number);
setCountry(simCard.isoCountryCode)
})
}
}, []);
}
return (
<PhoneInput
value={phone}
onChange={(phone) => setPhone(phone)}
/>
);
}
Description:
On iOS version 16.4.1, it has become impossible to retrieve the SIM card information using the getSimCards()
function. This issue affects iPhone 12 with iOS 16.4.1. The function works correctly on iPhone 12 with iOS 16.3.1.
Relevant Information:
iPhone 12 - iOS Version: 16.4.1 (Issue occurs)
{"simCards":[{"mobileCountryCode":"65535","mobileNetworkCode":"65535","carrierName":"--","allowsVOIP":true,"isoCountryCode":"--"},{"mobileCountryCode":"65535","allowsVOIP":true,"carrierName":"--","isoCountryCode":"--","mobileNetworkCode":"65535"}]}
iPhone 12 - iOS Version: 16.3.1 (Works as expected)
{"simCards":[{"carrierName":"","isoCountryCode":"","mobileCountryCode":"","mobileNetworkCode":"","allowsVOIP":true},{"isoCountryCode":"fr","carrierName":"Orange France","mobileNetworkCode":"01","mobileCountryCode":"208","allowsVOIP":true}]}
iPhone XR - iOS Version: 16.3.1 (Works as expected)
{"simCards":[{"isoCountryCode":"fr","carrierName":"Orange France","mobileNetworkCode":"01","mobileCountryCode":"208","allowsVOIP":true},{"carrierName":"","isoCountryCode":"","mobileCountryCode":"","mobileNetworkCode":"","allowsVOIP":true}]}
Code Example:
async function getSimCards() {
try {
const { simCards } = await Sim.getSimCards();
const sortedSimCards = simCards.map(
({
number, allowsVOIP, carrierName, isoCountryCode, mobileCountryCode, mobileNetworkCode,
}) => ({
number,
allowsVOIP,
carrierName,
isoCountryCode,
mobileCountryCode,
mobileNetworkCode,
}),
);
setSimInfo(sortedSimCards);
} catch (error) {
console.error('Error getting SIM info:', error);
setSimError('Erreur lors de la récupération des informations de la carte SIM');
}
}
Please help me fix this issue on the latest iOS version.
i have installed this plugin but i am not getting mobile number in the result.
If the mobile number is not set in the sim card settings, the number returns an empty string. However, android 13 fetches the user's phone number properly even if the number is not set in settings.
Capacitor 5 beta is already released: https://capacitorjs.com/docs/next/updating/plugins/5-0
Therefore, it is a good time to start adding support for Capacitor 5 and Android 13.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.