Contacts.checkPermission()
.then(permission => {
// Contacts.PERMISSION_AUTHORIZED || Contacts.PERMISSION_UNDEFINED || Contacts.PERMISSION_DENIED
if (permission === 'undefined') {
Contacts.requestPermission()
.then(response => {
console.log('Response', response);
if (response === 'authorized') {
Contacts.addContact(contact)
.then(result => {
return Alert.alert('Contact Added!', [{text: 'OK'}]);
})
.catch(e => {
console.log('Something Wrong Getting contacts', e);
return Alert.alert(
'Sorry, something went wrong',
'Sorry, We could not access your contacts list.',
[{text: 'OK'}],
);
});
}
})
.catch(er => {
console.log('Permission Error', er);
});
}
if (permission === 'authorized') {
Contacts.requestPermission()
.then(response => {
console.log('Response', response);
if (response === 'authorized') {
Contacts.addContact(contact)
.then(result => {
return Alert.alert('Contact Added!', [{text: 'OK'}]);
})
.catch(e => {
console.log('Something Wrong Getting contacts', e);
return Alert.alert(
'Sorry, something went wrong',
'Sorry, We could not access your contacts list.',
[{text: 'OK'}],
);
});
}
})
.catch(er => {
console.log('Permission Error', er);
});
}
if (permission === 'denied') {
Alert.alert(
'Permission Denied',
'If you want to add new contacts, Go to Settings > Inthority > Contacts and grant permission to acces contacts',
[{text: 'OK'}],
);
console.log('Sorry you did not gave permission to add new contacts');
}
})
.catch(err => {
console.log(err);
Alert.alert(
'Sorry, something went wrong',
'Sorry, We could not access your contacts list.',
[{text: 'OK'}],
);
});
In my info.plist I have set the Privacy - Contacts Usage Description description like this AppName Would like to access your contacts to sync them with your Client List and Add new contacts
I'm using a function like this:
In my
info.plist
I have set the Privacy - Contacts Usage Description description like this AppName Would like to access your contacts to sync them with your Client List and Add new contacts