Permissions and Getting Contacts

Following the documentation for getting and asking Permissions on Expo and I was able to get all but the Contacts.

https://docs.expo.io/versions/v15.0.0/sdk/contacts.html

The code seems to include support for asking permissions for Contacts, but the following snippet:

await Permissions.askAsync(Permissions.CONTACTS).then((result)=> {
		console.log(result);
	}).catch((err) => {
		console.log('error:', err);
	});

will console log the following:

error: {"framesToPop":1,"code":"E_PERMISSION_UNSUPPORTED"}

Using Expo V 15

Please advise.

Actually got it to work…

const contacts = await Expo.Contacts.getContactsAsync([
		Expo.Contacts.PHONE_NUMBERS,
		Expo.Contacts.EMAILS,
	]);
	if (contacts.length > 0) {
		Alert.alert(
			'Your first contact is...',
			`Name: ${contacts[0].name}\n` +
			`Phone: ${JSON.stringify(contacts[0].phoneNumbers)}\n` +
			`Email: ${JSON.stringify(contacts[0].emails)}`
		);
	}

This code will actually retrieve your contacts list and return the desired result.

Do not know if it goes by the Permissions functionality, if anyone knows more about the subject please share!

1 Like

Hi! Thanks for reporting this. We did actually add support for .CONTACTS as a new permissions flag but that is coming out in the upcoming (16) SDK, and isn’t supported in SDK 15 yet. But it was erroneously added to the documentation. Will fix that. But yes, in SDK 15 you just directly make the contacts-related API calls and they ask for permission if needed automatically. Starting from SDK 16 you will be able to ask for that explicitly yourself.