Skip to content

Commit

Permalink
Document existing issues with update contact
Browse files Browse the repository at this point in the history
  • Loading branch information
morenoh149 committed Jan 18, 2019
1 parent 864dc88 commit e69fde3
Showing 1 changed file with 38 additions and 26 deletions.
64 changes: 38 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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';

Expand All @@ -29,6 +27,7 @@ Contacts.getContactsMatchingString("filter", (err, contacts) => {
// contacts matching "filter"
})
```

### Android permissions
On android you must request permissions beforehand
```es
Expand All @@ -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
Expand Down Expand Up @@ -114,11 +114,8 @@ public class MainActivity extends ReactActivity {
new MainReactPackage(),
new ReactNativeContacts()); // <------ add this
}

......

}

```

##### ProGuard
Expand Down Expand Up @@ -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]
Expand All @@ -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
})
```
Expand Down

0 comments on commit e69fde3

Please sign in to comment.