Skip to content

sergeyshulzhenko/react-native-phone-caller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-phone-caller

npm version

React Native phone calls for iOS and Android

Getting started

$ npm install --save react-native-phone-caller or $ yarn add react-native-phone-caller

Mostly automatic installation

$ react-native link react-native-phone-caller

Manual installation

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-phone-caller and add RNPhoneCaller.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNPhoneCaller.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

  1. 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 the getPackages() 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
    );
  }
};

....
  1. 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')
  1. Insert the following lines inside the dependencies block in android/app/build.gradle:
implementation project(':react-native-phone-caller')

Usage

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');

Permissions

(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);
  }

About

React Native phone calls for iOS and Android

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published