native-reactive-contacts
v1.0.6
Published
a module for interfacing with native device contacts
Downloads
1
Readme
Native Reactive Contacts :man: :ok_woman: :woman: :boy: :princess: :older_woman: :bow: :older_man:
Table of contents:
Install for iOS development
install the package via npm
$ npm install native-reactive-contacts
go to
<your_project>/node_modules/native-reactive-contacts/
and drag thenative-reactive-contacts
directory to your workspace or project file tree. Make sure thatCopy items if needed is NOT checked!
, selectCreate folder references
and be sure that the sources are added to the correct target you wish to build against.on iOS10 and onward, you must add an
NSContactsUsageDescription
key to yourInfo.plist
. This provides the user some information as to why you wish to access privateContacts
information.
```xml
<key>NSContactsUsageDescription</key>
<string>your message to the user advising of your apps contacts usage intent</string>
```
be sure the
Contacts
framework is added to your target build phase:
Install for android development
coming soon! :confused:
Usage
Be sure to import NativeModules like so:
import { NativeModules } from 'react-native';
Expose this library to your component codebase:
var NativeReactiveContacts = NativeModules.NativeReactiveContacts;
Request for Contacts access:
NativeReactiveContacts.requestForContactsAccess((error, access) => {
if (error) {
console.log("error requesting access:" + error);
} else {
console.log("contacts access " + JSON.stringify(access));
}
});
CRUD Operations
CREATE a new contact:
let newContact = {
"firstName": "James",
"lastName": "Bond",
"phone": "9495728219",
"email": "[email protected]"
}
NativeReactiveContacts.createContact(newContact, (resp) => {
console.log("new contact created:" + JSON.stringify(resp));
});
/*
// your console should display the following:
new contact created: {"firstName":"James","lastName":"Bond","phone":"9495728219","email":"[email protected]"}
*/
READ all contacts from device:
NativeReactiveContacts.fetchAllContacts((obj) => {
console.log("all contacts fetched" + JSON.stringify(obj)); // parse the object for use in your app!
});
/*
// example of Anna Haro from the default device contacts on iOS:
[{"familyName":"Haro","nickname":"Annie","organizationName":"","departmentName":"","imageDataAvailable":0,"namePrefix":"","nameSuffix":"","socialProfiles":[],"phoneNumbers":[null],"identifier":"0021C776-7782-4195-9D1D-7E0C3138A323","urlAddresses":[],"postalAddresses":null,"middleName":"","jobTitle":"","note":"","phoneticMiddleName":"","phoneticGivenName":"","phoneticFamilyName":"","emailAddresses":[{"label":"home","value":"[email protected]","identifier":"0732F1F5-35C3-44E7-AC7B-3515FDC50FA0"}]
*/
UPDATE a contact:
let updateInfo = {
"givenName": "Joe",
"familyName": "Jackson"
}
NativeReactiveContacts.updateContactById("349E0749-874E-4993-8AE0-FAE839DF2E34", updateInfo, (contactId, contactInfo) => {
console.log("async response" + contactId + "info" + JSON.stringify(contactInfo));
});
DELETE an existing contact:
NativeReactiveContacts.deleteContact("678D06E9-1D7C-44F7-949D-CE1FC8068CB9",(response) => {
console.log("contact deletion response: " + JSON.stringify(response));
});