skip to Main Content

I’m using React Native Expo, and I want to open the default phone Contacts app.

On Android, I used:

await Linking.openURL("content://contacts/people/");

and that’s worked.

On iOS that doesn’t work.

I tried:

await Linking.openURL('contacts://');

but it doesn’t work.
How to do that on IOS?

2

Answers


  1. To open the default dialer app on iOS without a number pre-filled, you can try using the telprompt://{your number} URL scheme, which should prompt the dialer to open without immediately initiating a call. Here’s how you might use it in React Native

     import { Linking } from 'react-native';
    
    // Function to open the dialer
    const openDialer = async () => {
      const url = 'telprompt://<<your Number>>';
      const supported = await Linking.canOpenURL(url);
    
      if (supported) {
        await Linking.openURL(url);
      } else {
        console.log('Unable to open dialer');
      }
    };
    
    Login or Signup to reply.
  2. linking never worked for me either so I now use react-native-contacts. I believe it’s due to new android policies with permissions, as it has been disallowing a lot of things unless user has authorized, unlike < api level 32

    You need to first install the package using "npm install react-native-contacts" or "yarn add react-native-contacts" and then follow my steps below. (remember, you will need to ask for user’s permission"

    First check for permissions

    import Contacts from 'react-native-contacts';
    
    Contacts.requestPermission().then(permission => {
      if (permission === 'authorized') {
        // Permission was granted
        loadContacts();
      } else {
        // Permission was denied
        console.log('Contacts permission denied');
      }
    });
    

    Now if the user authorizes, you can either follow my example below, or do as you please

    const loadContacts = () => {
      Contacts.getAll((err, contacts) => {
        if (err) {
          throw err;
        }
        // Use contacts
    
         console.log(contacts);
    
        //here you can save the array in a state or do whatever you feel like.
      });
    };
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search