From 91bb7f90689c7370e42f8a14beb37f11e871c59b Mon Sep 17 00:00:00 2001 From: robertwood-mobile <“robertwood0619@gmail.com”> Date: Fri, 18 Jan 2019 15:41:53 -0500 Subject: [PATCH] Document existing issues with update contact ref https://github.com/rt2zz/react-native-contacts/issues/332#issuecomment-455675041 --- README.md | 64 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 666b1f2..743b0aa 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ Ask questions on [stackoverflow](https://stackoverflow.com/questions/tagged/reac ## Usage `getAll` is a database intensive process, and can take a long time to complete depending on the size of the contacts list. Because of this, it is recommended you access the `getAll` method before it is needed, and cache the results for future use. - ```es import Contacts from 'react-native-contacts'; @@ -18,7 +17,6 @@ Contacts.getAll((err, contacts) => { ``` `getContactMatchingString` is meant to alleviate the amount of time it takes to get all contacts, by filtering on the native side based on a string. - ```es import Contacts from 'react-native-contacts'; @@ -29,6 +27,7 @@ Contacts.getContactsMatchingString("filter", (err, contacts) => { // contacts matching "filter" }) ``` + ### Android permissions On android you must request permissions beforehand ```es @@ -51,26 +50,27 @@ PermissionsAndroid.request( }) }) ``` + ## Installation To use this module you have to install it and configure the permissions. Please read this entire section. ### Automatic with npm - - npm install react-native-contacts --save +``` +npm install react-native-contacts --save +``` _the `--save` is necessary for [automatic linking](https://facebook.github.io/react-native/docs/linking-libraries-ios.html#automatic-linking)_ with yarn - - yarn add react-native-contacts +``` +yarn add react-native-contacts +``` and then do - - react-native link +``` +react-native link +``` If you get an error about -`import Contacts from 'react-native-contacts'; is undefined.` try manual linking -below. - -Also, supporting older versions of Android (API level <= 22) requires extra permissions; see the [Android permissions](#android-1) section. +`import Contacts from 'react-native-contacts'; is undefined.` try manual linking below. ### Manual #### iOS @@ -114,11 +114,8 @@ public class MainActivity extends ReactActivity { new MainReactPackage(), new ReactNativeContacts()); // <------ add this } - ...... - } - ``` ##### ProGuard @@ -255,11 +252,13 @@ Contacts.openContactForm(newPerson, (err) => { ``` You may want to edit the contact before saving it into your phone book. So using `openContactForm` allow you to prompt default phone create contacts UI and the new to-be-added contact will be display on the contacts UI view. Click save or cancel button will exit the contacts UI view. -## Updating and Deleting Contacts +## Updating Contacts Example ```es Contacts.getAll((err, contacts) => { - if (err) throw err; + if (err) { + throw err; + } // update the first record let someRecord = contacts[0] @@ -271,20 +270,33 @@ Contacts.getAll((err, contacts) => { if (err) throw err; // record updated }) - - //delete the second record - Contacts.deleteContact(contacts[1], (err, recordId) => { - if (err) throw err; - // contact deleted - }) }) ``` -Update and delete reference contacts by their recordID (as returned by the OS in getContacts). Apple does not guarantee the recordID will not change, e.g. it may be reassigned during a phone migration. Consequently you should always grab a fresh contact list with `getContacts` before performing update and delete operations. +Update reference contacts by their recordID (as returned by the OS in getContacts). Apple does not guarantee the recordID will not change, e.g. it may be reassigned during a phone migration. Consequently you should always grab a fresh contact list with `getContacts` before performing update operations. + +### Bugs +There are issues with updating contacts on Android: +1. custom labels get overwritten to "Other", +1. postal address update code doesn't exist. (it exists for addContact) +1. phoneNumbers and emails insert instead of update. +See https://github.com/rt2zz/react-native-contacts/issues/332#issuecomment-455675041 for current discussions. -You can also delete a record using only it's recordID +## Delete Contacts +You can delete a record using only it's recordID ```es Contacts.deleteContact({recordID: 1}, (err, recordId) => { - if (err) throw err; + if (err) { + throw err; + } + // contact deleted +}) +``` +Or by passing the full contact object with a `recordID` field. +```es +Contacts.deleteContact(contact, (err, recordId) => { + if (err) { + throw err; + } // contact deleted }) ```