React Native Carrier Info
React Native module bridge to obtain information about the user’s home cellular service provider.
Makes use of the following native classes:
- iOS
- Android
Version
1.0.0
- Android support
- Promosify all APIs
- RN 0.47 support
API
All APIs are async functions
allowsVOIP (iOS only)
boolean - Indicates if the carrier allows VoIP calls to be made on its network
- If you configure a device for a carrier and then remove the SIM card, this property retains the Boolean value indicating the carrier’s policy regarding VoIP.
- Always return
true
on Android.
carrierName
string - The name of the user’s home cellular service provider
- This string is provided by the carrier and formatted for presentation to the user. The value does not change if the user is roaming; it always represents the provider with whom the user has an account.
- If you configure a device for a carrier and then remove the SIM card, this property retains the name of the carrier.
- The value for this property is 'nil' if the device was never configured for a carrier.
isoCountryCode
string - The ISO country code for the user’s cellular service provider
- This property uses the ISO 3166-1 country code representation.
- The value for this property is 'nil' if any of the following apply:
- The device is in Airplane mode.
- There is no SIM card in the device.
- The device is outside of cellular service range.
mobileCountryCode
string - The mobile country for the user’s cellular service provider
- MCCs are defined by ITU-T Recommendation E.212, “List of Mobile Country or Geographical Area Codes.”
- The value for this property is 'nil' if any of the following apply:
- There is no SIM card in the device.
- The device is outside of cellular service range.
- The value may be 'nil' on hardware prior to iPhone 4S when in Airplane mode.
mobileNetworkCode
string - The mobile network for the user’s cellular service provider
- The value for this property is 'nil' if any of the following apply:
- There is no SIM card in the device.
- The device is outside of cellular service range.
- The value may be 'nil' on hardware prior to iPhone 4S when in Airplane mode.
mobileNetworkOperator
string - return MCC + MNC eg 46697
Getting Started (and running the demo project)
iOS
- From inside your project run
npm install react-native-carrier-info --save
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules/react-native-carrier-info/ios
and addRNCarrierInfo.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNCarrierInfo.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Click
RNCarrierInfo.xcodeproj
in the project navigator and go theBuild Settings
tab. Make sure 'All' is toggled on (instead of 'Basic'). Look forHeader Search Paths
and make sure it contains both$(SRCROOT)/../react-native/React
and$(SRCROOT)/../../React
- mark both asrecursive
. - Set up the project to run on your device (iOS simulator does not report cellular provider info)
- Run your project (
Cmd+R
)
Android
- app/build.gradle
dependencies { ... compile project(':react-native-carrier-info') <-- add this ... }
- settings.gradle
include ':react-native-carrier-info'project(':react-native-carrier-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-carrier-info/android')
- MainApplication.java
...import com.ianlin.RNCarrierInfo.RNCarrierInfoPackage; <-- add this... @Overrideprotected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), ... new RNCarrierInfoPackage(), <-- add this ... );}
Usage Example
; // inside your code where you would like to retrieve carrier infoCarrierInfo; CarrierInfo; CarrierInfo; CarrierInfo; CarrierInfo; CarrierInfo;
There is an example project supplied with the repo in the RNCarrierInfoDemo folder. The sample app needs to be run on a device as the simulator does not report cellular provider info.
Original Author:
License
ISC License (functionality equivalent to MIT License)