NativeScript-Telephony
This is a Nativescript plugin to get data from the SIM card like the carrier name, mcc, mnc and country code and other system dependent additional info.
Contributors
Peter Bakondy for his work on cordova-plugin-sim. Basically this is his plugin. I followed his source code as a guide.
Supported Platforms
- Android
- iOS
Installation
tns plugin add nativescript-telephony
Usage
Typescript
;
ES6 Promises
If you are unfamiliar with Promises, read up on these:
iOS Quirks
Promise.Resolves
{
"carrierName": String,
"countryCode": String,
"mcc": String,
"mnc": String,
"allowsVOIP": Boolean,
}
Sadly there's nothing more we can get here.
Promise.Rejects
When using an emulator or a sim card does not exist.
Android Quirks
All permission dialogues are built into the Telephony
function.
Promise.Resolves
DENIED
to READ_PHONE_STATE
When Permission is {
"countryCode": String,
"simOperator": String,
"carrierName": String,
"callState": Number,
"dataActivity": Number,
"networkType": Number,
"phoneType": Number,
"simState": Number,
"isNetworkRoaming": Boolean,
"mcc": String,
"mnc": String,
}
GRANTED
to READ_PHONE_STATE
When Permission is {
// START GRANTED PERMISSIONS
"phoneNumber": String,
"deviceId": String,
"deviceSoftwareVersion": String,
"simSerialNumber": String,
"subscriberId": String,
// END GRANTED PERMISSIONS
"countryCode": String,
"simOperator": String,
"carrierName": String,
"callState": Number,
"dataActivity": Number,
"networkType": Number,
"phoneType": Number,
"simState": Number,
"isNetworkRoaming": Boolean,
"mcc": String,
"mnc": String,
}
Promise.Rejects
Never.
Demo
npm run setup# iOS npm run demo.ios# Android npm run demo.android
License
This plugin is licensed under the MITlicense by Rob Laverty