You can use the YES lib of ionic-native
.
Example:
getInformacoesSIM() {
this.sim.requestReadPermission().then(() => {
this.sim.getSimInfo().then((info) => {
console.log(info);
}, err => {
console.log(err);
})
}, () => console.log('Permission denied'))
}
If you prefer to avoid promising, you can also use async / await
async getInformacoesSIM() {
try {
let permission = await this.sim.requestReadPermission();
let info = await this.sim.getSimInfo();
console.log(info);
} catch (er) {
console.log(er);
}
}
According to the documentation, on return you will have the following payload
:
{
"carrierName": "Android",
"countryCode": "us",
"mcc": "310",
"mnc": "260",
"phoneNumber": "15555215554",
"deviceId": "0000000000000000",
"simSerialNumber": "89014103211118510720",
"subscriberId": "310260000000000",
"callState": 0,
"dataActivity": 0,
"networkType": 3,
"phoneType": 1,
"simState": 5,
"isNetworkRoaming": false
}
NOTE: the content of phoneNumber is unreliable (see this and this
article). Sometimes phoneNumber is only an empty string.
According to README.txt
of lib, not all phones are "able" to return the phone number, in those cases the phoneNumber will be represented by an empty string.