joshuapinter / react-native-unified-contacts

Your best friend when working with the latest and greatest Contacts Framework in iOS 9+ in React Native.
MIT License
158 stars 56 forks source link

Delete Contact IOS #77

Closed rajanrai93 closed 6 years ago

rajanrai93 commented 6 years ago

I've been able to allow the user to input what they want the contact name and number to be in my app and add the contact, but when they want to delete the contact, the app crashes. I'm not sure if theres an issue with the library or not, it seems to not read the contact identifier properly. I've asked on SO but no answer :( I apologize if there is just a stupid error in my code.

screen shot 2018-05-17 at 12 44 56 pm screen shot 2018-05-17 at 12 39 56 pm
paintedbicycle commented 6 years ago

Hey @rajanrai93 - before I recreate and debug this - have you confirmed that the contactIdentifer exists? It looks like you're first setting the identifier and I'm not 100% sure that this works. I think Apple provides the identifier on creation and then we can use it for both updating and deleting. But at contact creation time, I don't think it can be provided. I might be wrong about that, but please try:

  1. Creating the contact without the identifier.
  2. Logging the identifier so you that know what it is
  3. Deleting a contact with the identifier created by iOS

If it still crashes, let me know.

UPDATE: Looking at your code again it doesn't appear you set the identifier (you just seem to declare it twice), but the question still stands - is that a contact identifier that exists for one of your contacts? If you can confirm that, we can then look deeper.

As always, please also post your debug logs so we can read what the error is.

Paul

rajanrai93 commented 6 years ago

You're absolutely right! can't set a contact id. just thought it would have been an easier way to fetch the id. So if we're trying to fetch the ID after the contact is created to use it in the future(deleting contact in app), we would just use a state prop?

paintedbicycle commented 6 years ago

@rajanrai93 Totally depends on what your app's requirements are - but yes!

When adding, you will receive back the contact with the newly created identifier and you can store it, if you're going to act on it right away. Or you can later query your contacts (either get all of them or search for a specific one) and get the IDs at that time, then do something. Basically once the contact is created, the identifier is returned at all times and you can then act on it using the identifier.

In one case that I use, I show a list of all contacts to my users. When the user clicks on a contact, I then store that one specific user's data in state. When manipulating, I refer to that.

Paul