Skip to content

tiaanduplessis/react-native-phone-call

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-phone-call

package version package downloads standard-readme compliant package license make a pull request

Initiate a phone call in React Native.

Table of Contents

Background

This is a small wrapper that allows you to initiate a phone call in React Native.

Running on iOS simulator

When running on the iOS simulator, you will get a the URL is invalid error. This will work on an actual device. The iOS simulator does not have access to the dialer app..

Running on Android SDK 30+

Android SDK 30 introduced changes around how apps can query and interact with other apps. This means Linking.canOpenURL returns false for all links unless a <queries> element is added to AndroidManifest.xml. Adding the following intent to android/app/src/main/AndroidManifest.xml should resolve the issue:

<queries>
      <intent>
        <action android:name="android.intent.action.DIAL" />
      </intent>
</queries>

Limitations

This module only provides a simple wrapper around the Linking API and is thus limited in the functionality it can provide. If you are looking for additional functionality, such as being able to initiate a phone call without user confirmation, please use other packages like react-native-immediate-phone-call.

Install

Install the package locally within you project folder with your package manager:

With npm:

npm install react-native-phone-call

With yarn:

yarn add react-native-phone-call

Usage

To use the module, call the function with an object containing the number to call as a argument.

import call from 'react-native-phone-call'

const args = {
  number: '9093900003', // String value with the number to call
  prompt: false, // Optional boolean property. Determines if the user should be prompted prior to the call 
  skipCanOpen: true // Skip the canOpenURL check
}

call(args).catch(console.error)

Example with phone and extension.

Use commas to add time between pressing different digits. (ex. dial a number and wait to be connected and menu to start being read. Press a number for an extension. Even wait longer for another menus and press another number for another extension.)

const args = {
  number: '9093900003,,,3,,,274', // Use commas to add time between digits.
  prompt: false
}

call(args).catch(console.error)

API

For all configuration options, please see the API docs.

Contributing

Got an idea for a new feature? Found a bug? Contributions are welcome! Please open up an issue or make a pull request.

License

MIT © Tiaan du Plessis