-1

I trying delete a contact from my list with react-native-contact library.

I using my phone as emulator so i can access my contact list. But when i try delete one my phone giving alert and telling like .

("ProjectName" trying delete your contacts. You cant delete contacts with 3rd party programms. Instead of that use MIUI contact list for delete )

But i must delete with my application. How can i do it ? My phone is : Xiaomi mi 8 and my codes :

For Delete :

import Contacts from 'react-native-contacts';
.
.
.
const deleteItem = item=> {
    Alert.alert(
      'Kayıt Silinecektir!',
      `${item.displayName} kaydı silinecektir. Emin misiniz ?`,
      [
        {
          text: 'Vazgeç',
          onPress: () => console.log('Cancel Pressed'),
          style: 'cancel',
        },
        {
          text: 'Sil',
          onPress: async () => {
            const resp = await Contacts.deleteContact({recordID: item.contactId});
          },
        },
      ],
    );
  };

1 Answers1

0

You must have permissions beforehand :

import { PermissionsAndroid } from 'react-native';
import Contacts from 'react-native-contacts';

Contacts.getAll().then(contacts => {
  // contacts returned
})
PermissionsAndroid.request(
  PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
  {
    'title': 'Contacts',
    'message': 'This app would like to view your contacts.',
    'buttonPositive': 'Please accept bare mortal'
  }
)
.then(Contacts.getAll)
.then(contacts => {
  ...
})

Also watch this - How to get permission for deleting contacts in xiaomi (MIUI) devices?

Quintis
  • 517
  • 3
  • 12
  • thanks for reply. But in useEffect i have permissions already. I have read and write permissions. But still same result. And in link its said go check manual. When i check manual i have contact permissions on my app. – juniorFrontEndDD Oct 10 '21 at 14:28
  • @juniorFrontEndDD Perhaps you must call Contacts right after permission – Quintis Oct 10 '21 at 14:31