react-native-contacts
Advanced tools
Comparing version 5.2.8 to 6.0.0
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "5.2.8", | ||
"version": "6.0.0", | ||
"description": "React Native Contacts (android & ios)", | ||
@@ -10,0 +10,0 @@ "nativePackage": true, |
100
README.md
@@ -12,6 +12,3 @@ ![react-native-contacts](https://github.com/rt2zz/react-native-contacts/raw/master/example/logo.png) | ||
Contacts.getAll((err, contacts) => { | ||
if (err) { | ||
throw err; | ||
} | ||
Contacts.getAll().then(contacts => { | ||
// contacts returned | ||
@@ -35,10 +32,6 @@ }) | ||
} | ||
).then(() => { | ||
Contacts.getAll((err, contacts) => { | ||
if (err === 'denied'){ | ||
// error | ||
} else { | ||
// contacts returned in Array | ||
} | ||
}) | ||
) | ||
.then(Contacts.getAll) | ||
.then(contacts => { | ||
... | ||
}) | ||
@@ -146,6 +139,6 @@ ``` | ||
##### API 22 and below | ||
Add `READ_PROFILE` and/or `WRITE_PROFILE` permissions to `AndroidManifest.xml` | ||
Add `READ_CONTACTS` and/or `WRITE_PROFILE` permissions to `AndroidManifest.xml` | ||
```xml | ||
... | ||
<uses-permission android:name="android.permission.READ_PROFILE" /> | ||
<uses-permission android:name="android.permission.READ_CONTACTS" /> | ||
... | ||
@@ -175,27 +168,20 @@ ``` | ||
## API | ||
* `getAll` (callback) - returns *all* contacts as an array of objects | ||
* `getAll`: Promise<Contact[]> - returns *all* contacts as an array of objects | ||
* `getAllWithoutPhotos` - same as `getAll` on Android, but on iOS it will not return uris for contact photos (because there's a significant overhead in creating the images) | ||
* `getContactById(contactId, callback)` - returns contact with defined contactId (or null if it doesn't exist) | ||
* `getCount(callback)` - returns the number of contacts | ||
* `getPhotoForId(contactId, callback)` - returns a URI (or null) for a contacts photo | ||
* `addContact` (contact, callback) - adds a contact to the AddressBook. | ||
* `openContactForm` (contact, callback) - create a new contact and display in contactsUI. | ||
* `openExistingContact` (contact, callback) - where contact is an object with a valid recordID | ||
* `editExistingContact` (contact, callback) - add numbers to the contact, where the contact is an object with a valid recordID and an array of phoneNumbers | ||
* `updateContact` (contact, callback) - where contact is an object with a valid recordID | ||
* `deleteContact` (contact, callback) - where contact is an object with a valid recordID | ||
* `getContactsMatchingString` (string, callback) - where string is any string to match a name (first, middle, family) to | ||
* `getContactsByPhoneNumber` (string, callback) - where string is a phone number to match to. | ||
* `getContactsByEmailAddress` (string, callback) - where string is an email address to match to. | ||
* `checkPermission` (callback) - checks permission to access Contacts _ios only_ | ||
* `requestPermission` (callback) - request permission to access Contacts _ios only_ | ||
* `writePhotoToPath` (callback) - writes the contact photo to a given path _android only_ | ||
* `getContactById(contactId)`: Promise<Contact> - returns contact with defined contactId (or null if it doesn't exist) | ||
* `getCount()`: Promise<number> - returns the number of contacts | ||
* `getPhotoForId(contactId)`: Promise<string> - returns a URI (or null) for a contacts photo | ||
* `addContact(contact)`: Promise<Contact> - adds a contact to the AddressBook. | ||
* `openContactForm(contact)` - create a new contact and display in contactsUI. | ||
* `openExistingContact(contact)` - where contact is an object with a valid recordID | ||
* `editExistingContact(contact)`: Promise<Contact> - add numbers to the contact, where the contact is an object with a valid recordID and an array of phoneNumbers | ||
* `updateContact(contact)`: Promise<Contact> - where contact is an object with a valid recordID | ||
* `deleteContact(contact)` - where contact is an object with a valid recordID | ||
* `getContactsMatchingString(string)`: Promise<Contact[]> - where string is any string to match a name (first, middle, family) to | ||
* `getContactsByPhoneNumberstring)`: Promise<Contact[]> - where string is a phone number to match to. | ||
* `getContactsByEmailAddress(string)`: Promise<Contact[]> - where string is an email address to match to. | ||
* `checkPermission()`: Promise<string> - checks permission to access Contacts _ios only_ | ||
* `requestPermission()`: Promise<string> - request permission to access Contacts _ios only_ | ||
* `writePhotoToPath()` - writes the contact photo to a given path _android only_ | ||
Callbacks follow node-style: | ||
```sh | ||
callback <Function> | ||
err <Error> | ||
response <Object> | ||
``` | ||
## Example Contact Record | ||
@@ -258,6 +244,3 @@ ```js | ||
Contacts.addContact(newPerson, (err) => { | ||
if (err) throw err; | ||
// save successful | ||
}) | ||
Contacts.addContact(newPerson) | ||
``` | ||
@@ -276,4 +259,3 @@ | ||
Contacts.openContactForm(newPerson, (err, contact) => { | ||
if (err) throw err; | ||
Contacts.openContactForm(newPerson).then(contact => { | ||
// contact has been saved | ||
@@ -287,7 +269,3 @@ }) | ||
```js | ||
Contacts.getAll((err, contacts) => { | ||
if (err) { | ||
throw err; | ||
} | ||
Contacts.getAll().then(contacts => { | ||
// update the first record | ||
@@ -299,4 +277,3 @@ let someRecord = contacts[0] | ||
}) | ||
Contacts.updateContact(someRecord, (err) => { | ||
if (err) throw err; | ||
Contacts.updateContact(someRecord).then(() => { | ||
// record updated | ||
@@ -320,4 +297,3 @@ }) | ||
Contacts.editExistingContact(newPerson, (err, contact) => { | ||
if (err) throw err; | ||
Contacts.editExistingContact(newPerson).then(contact => { | ||
//contact updated | ||
@@ -339,6 +315,3 @@ }); | ||
```js | ||
Contacts.deleteContact({recordID: 1}, (err, recordId) => { | ||
if (err) { | ||
throw err; | ||
} | ||
Contacts.deleteContact({recordID: 1}).then(recordId => { | ||
// contact deleted | ||
@@ -349,6 +322,3 @@ }) | ||
```js | ||
Contacts.deleteContact(contact, (err, recordId) => { | ||
if (err) { | ||
throw err; | ||
} | ||
Contacts.deleteContact(contact).then((recordId) => { | ||
// contact deleted | ||
@@ -367,13 +337,11 @@ }) | ||
## Permissions Methods (optional) | ||
`checkPermission` (callback) - checks permission to access Contacts. | ||
`requestPermission` (callback) - request permission to access Contacts. | ||
`checkPermission` - checks permission to access Contacts. | ||
`requestPermission` - request permission to access Contacts. | ||
Usage as follows: | ||
```js | ||
Contacts.checkPermission((err, permission) => { | ||
if (err) throw err; | ||
Contacts.checkPermission().then(permission => { | ||
// Contacts.PERMISSION_AUTHORIZED || Contacts.PERMISSION_UNDEFINED || Contacts.PERMISSION_DENIED | ||
if (permission === 'undefined') { | ||
Contacts.requestPermission((err, permission) => { | ||
Contacts.requestPermission().then(permission => { | ||
// ... | ||
@@ -380,0 +348,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
235962
377