React Native phone calls for iOS and Android
$ npm install --save react-native-phone-caller
or
$ yarn add react-native-phone-caller
$ react-native link react-native-phone-caller
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-phone-caller
and addRNPhoneCaller.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNPhoneCaller.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import com.PhoneCaller.RNPhoneCallerPackage;
to the imports at the top of the file `` - Add
new RNPhoneCallerPackage()
to the list returned by thegetPackages()
method
import com.PhoneCaller.RNPhoneCallerPackage; // <--- 1
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNPhoneCallerPackage() // <--- 2
);
}
};
....
- Append the following lines to
android/settings.gradle
:
include ':react-native-phone-caller'
project(':react-native-phone-caller').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-phone-caller/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:
implementation project(':react-native-phone-caller')
PhoneCaller.call(tel)
Arguments:
- tel: String - a phone number to call
Returns: Promise
- fulfilled: String -
Success
- rejected: Error
import PhoneCaller from 'react-native-phone-caller';
PhoneCaller.call('+98887776655');
(Android only) PermissionsAndroid
Request the CALL_PHONE permission beforehand
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.CALL_PHONE,
{
...
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
await PhoneCaller.call('+98887776655');
...
} else {
Alert.alert('Error', 'Call phone permission denied');
}
} catch (err) {
console.warn(err);
}