react-native-contacts
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "React Native Contacts (android & ios)", | ||
@@ -10,0 +10,0 @@ "nativePackage": true, |
101
README.md
@@ -8,3 +8,2 @@ # React Native Contacts | ||
`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 | ||
@@ -14,21 +13,33 @@ import Contacts from 'react-native-contacts'; | ||
Contacts.getAll((err, contacts) => { | ||
if (err) throw err; | ||
if (err) { | ||
throw err; | ||
} | ||
// contacts returned | ||
console.log(contacts) | ||
}) | ||
``` | ||
See the full [API](#api) for more methods. | ||
`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. | ||
### Android permissions | ||
On android you must request permissions beforehand | ||
```es | ||
import { PermissionsAndroid } from 'react-native'; | ||
import Contacts from 'react-native-contacts'; | ||
Contacts.getContactsMatchingString("filter", (err, contacts) => { | ||
if (err) throw err; | ||
// contacts matching "filter" | ||
console.log(contacts) | ||
PermissionsAndroid.request( | ||
PermissionsAndroid.PERMISSIONS.READ_CONTACTS, | ||
{ | ||
'title': 'Contacts', | ||
'message': 'This app would like to view your contacts.' | ||
} | ||
).then(() => { | ||
Contacts.getAll((err, contacts) => { | ||
if (err === 'denied'){ | ||
// error | ||
} else { | ||
// contacts returned in Array | ||
} | ||
}) | ||
}) | ||
``` | ||
## Installation | ||
@@ -39,18 +50,18 @@ To use this module you have to install it and configure the permissions. Please read this entire section. | ||
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. | ||
`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. | ||
### Manual | ||
@@ -98,8 +109,16 @@ #### iOS | ||
} | ||
...... | ||
} | ||
``` | ||
##### ProGuard | ||
If you use Proguard, the snippet below on proguard-rules.pro | ||
Without it, your apk release version could failed | ||
``` | ||
-keep class com.rt2zz.reactnativecontacts.** {*;} | ||
-keepclassmembers class com.rt2zz.reactnativecontacts.** {*;} | ||
``` | ||
### Permissions | ||
@@ -229,7 +248,9 @@ #### iOS | ||
## Updating and Deleting Contacts | ||
## Updating Contacts | ||
Example | ||
```es | ||
Contacts.getAll((err, contacts) => { | ||
if (err) throw err; | ||
if (err) { | ||
throw err; | ||
} | ||
@@ -246,19 +267,31 @@ // update the first record | ||
}) | ||
//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. | ||
You can also delete a record using only it's recordID | ||
### 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) | ||
See https://github.com/rt2zz/react-native-contacts/issues/332#issuecomment-455675041 for current discussions. | ||
## 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 | ||
}) | ||
``` | ||
@@ -265,0 +298,0 @@ ## Displaying Thumbnails |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
177617
347