martinarroyo / react-native-telephony-apis

📱 This project allows access to the telephony APIs of Cocoa and Android

Home Page:https://www.motius.de/en/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-native-telephony-apis

An interface to the CoreTelephony framework and TelephonyManager for React Native.

Our npm package is coming soon! You can install it using npm install git+https://github.com/motius/react-native-telephony-apis.git Feel free to join our efforts in the meantime :)

Setup

Automatic linking

react-native link should take care of the setup automatically, otherwise please refer to the manual setup.

Manual setup

iOS

Add the RNReactNativeTelephony.xcodeproj to your project's 'Libraries' folder In your project settings, select your target -> Build Phases -> Link Binary with Libraries and add libRNReactNativeTelephony.a

Copy ios/DiallingCodes.plist to the folder where your AppDelegate.m is located.

Android

Edit the following files:

  • android/settings.gradle

Add the following lines:

include ':react-native-telephony'
project(':react-native-telephony').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-telephony-apis/android')
  • android/app/build.gradle

Add the following line to your dependencies:

dependencies {
    // ...  
    compile project(':react-native-telephony')
}
  • android/app/src/main/java/your/package/identifier/MainApplication.java

Import de.motius.RNReactNativeTelephony.RNReactNativeTelephonyPackage; and create an instance:

@Override
protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
  //...
    new RNReactNativeTelephonyPackage()
  );
}

Usage

Get country code (iOS, Android):

import Telephony from 'react-native-telephony-apis';

// ...

Telephony.getCountryCode().then(result => {
	// isoCountryCode: ISO 3166 country code
	// mobileCountryCode: Country code (MCC): https://en.wikipedia.org/wiki/Mobile_country_code
	// mobileNetworkCode: Carrier network code (MNC): https://en.wikipedia.org/wiki/Mobile_network_code
	// callPrefix: Country call prefix for the phone number
	const {isoCountryCode, mobileCountryCode, mobileNetworkCode, callPrefix} = result;
})

Some phones might not retrieve all values (and emulators will not return any). In that case the value will be set to null.

Get phone number (Android):

Unfortunately iOS does not allow for the phone number to be retrieved. This method is thus Android-only.

import Telephony from 'react-native-telephony-apis';

// ...

Telephony.getPhoneNumber().then(result =>{
	// phoneNumber: The phone number associated to the SIM card. Unfortunately, the module does not support multiple SIM cards. The number may be returned with or without the country code.
	const {phoneNumber} = result;
})

About

📱 This project allows access to the telephony APIs of Cocoa and Android

https://www.motius.de/en/

License:MIT License


Languages

Language:Java 51.2%Language:C# 33.8%Language:Objective-C 13.6%Language:JavaScript 1.3%