Giter Site home page Giter Site logo

react-native-contacts-wrapper's Introduction

react-native-contacts-wrapper

alt tag

This is a simple wrapper for the native iOS and Android Contact Picker UIs. When calling the API functions, the appropriate picker is launched. If a contact is picked, the promise is resolved with the requested data about the picked contact.

This uses the ContactsContract API for Android, AddressBook library for iOS8 and below and the new Contacts library for ios9+.

The API is currently very basic. This was started just as a way of selecting a contact's email address. The getContact function was added as a more generic way of returning contact data. Currently this returns Name, Phone and Email for picked contact. In future more fields will be added to this, and possibly more specific methods similar to getEmail.

Feel free to extend the functionality so it's more useful for everyone - all PRs welcome!

Installation

Automatic (works for iOS without condition; for Android with RN 0.28 and before)

If you have rnpm installed, all you need to do is

npm install react-native-contacts-wrapper --save
rnpm link react-native-contacts-wrapper

Manual

Android (with RN 0.29 and above)

in settings.gradle

include ':react-native-contacts-wrapper'
project(':react-native-contacts-wrapper').projectDir = new File(settingsDir, '../node_modules/react-native-contacts-wrapper/android/app')

in android/app/build.gradle

dependencies {
    compile project(':react-native-contacts-wrapper')

in MainApplication.java add package to getPacakges()

import com.lynxit.contactswrapper.ContactsWrapperPackage;
...

@Override
protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        ...,
       new ContactsWrapperPackage()
   );
}

in AndroidManifest.xml make sure you have the following setting even if you have done react-native upgrade

<application
     android:name=".MainApplication"

Also add

<uses-permission android:name="android.permission.READ_CONTACTS" />

iOS

  1. Open your xCode project
  2. Click project name in project navigator
  3. Select the main target in the left hand menu
  4. Scroll to Linked Frameworks and Libraries
  5. click + at bottom
  6. Click ‘Add Other'
  7. Find and add your new project’s .xcodeproj file from node_modules
  8. This will now appear in project explorer, drag in under the Libraries group.
  9. In same screen, click + again, you should now see the .a file for you project, Add this
  10. Clean and Rebuild your Xcode project

##API

getContact (Promise) - returns basic contact data as a JS object. Currently returns name, first phone number and first email for contact. getEmail (Promise) - returns first email address (if found) for contact as string.

##Usage

Methods should be called from React Native as any other promise. Prevent methods from being called multiple times (on Android).

###Example

An example project can be found in this repo: https://github.com/LynxITDigital/react-native-contacts-wrapper-example/tree/master

import ContactsWrapper from 'react-native-contacts-wrapper';
...
if (!this.importingContactInfo) {
  this.importingContactInfo = true;

  ContactsWrapper.getEmail()
  .then((email) => {
    this.importingContactInfo = false;
    console.log("email is", email);
    })
    .catch((error) => {
      this.importingContactInfo = false;
      console.log("ERROR CODE: ", error.code);
      console.log("ERROR MESSAGE: ", error.message);
      });

react-native-contacts-wrapper's People

Contributors

arv avatar bluefiresky avatar brycepavey avatar doko-demo-doa avatar hoang3553 avatar jaxgit avatar jpb12 avatar olij avatar proyoyo avatar rgabs avatar tomasreimers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-contacts-wrapper's Issues

Missing Purpose String in Info.plist

I just got a response from APP store that this is missing in my app.

Your app's code references one or more APIs that access sensitive user data. The app's Info.plist file should contain a NSLocationAlwaysUsageDescription key with a user-facing purpose string explaining clearly and completely why your app needs the data. Starting Spring 2019, all apps submitted to the App Store that access user data are required to include a purpose string. If you're using external libraries or SDKs, they may reference APIs that require a purpose string. While your app might not use these APIs, a purpose string is still required. You can contact the developer of the library or SDK and request they release a version of their code that doesn't contain the APIs. Learn more

Any idea if this library has already included this purpose string

App crash on contact select

I'm trying to run on android device, when i select a contact from list the app gets crashed.

can anyone help me out

Compilation failed - Android

I followed the manual linking steps for Android, but when I run react-native run-android I get the following error:

C:\Users\me\Documents\GitHub\myapp\node_modules\react-native-contacts-wrapper\android\app\src\main\java\com\lynxit\contactswrapper\ContactsWrapper.java:31: error: ContactsWrapper is not abstract and does not override abstract method onActivityResult(Activity,int,int,Intent) in ActivityEventListener
public class ContactsWrapper extends ReactContextBaseJavaModule implements ActivityEventListener {
       ^
C:\Users\me\Documents\GitHub\myapp\node_modules\react-native-contacts-wrapper\android\app\src\main\java\com\lynxit\contactswrapper\ContactsWrapper.java:80: error: method does not override or implement a method from a supertype
    @Override
    ^
2 errors
:react-native-contacts-wrapper:compileReleaseJavaWithJavac FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-contacts-wrapper:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

ContactsWrapper.getContact() promise never gets resolved

All code before and after the invocation of the getContact function runs, but neither the .then nor the .catch blocks execute, leading me to believe the promise never get resolved or rejected.

Also, I had to manually link libraries because I received the following error after attempting to automatically link with rnpm: It seems something went wrong while linking. Error: Expected [\n\r] but end of input found. I added the ContactsWrapper.xcodeproj file from node_modules to the libraries directory in xcode and added the libRCTContactsWrapper.a to my Link Binary With Libraries section in Build Phases. No build errors or runtime errors, but I still think installation might have something to do with this unhandled promise.

ContactsWrapper.getContact() from modal doesn't open and gives warning on ios

ContactsWrapper.getContact() doesn't open and gives warning on ios when called from a react native modal.

the warning says:
2017-02-16 19:54:28.781 XXXX[6918:169402] Warning: Attempt to present <CNContactPickerViewController: 0x7f85185a2340> on <UIViewController: 0x7f8512f0dd80> which is already presenting <RCTModalHostViewController: 0x7f85183b0fb0>

The same functionality works when called from a navigator class page. But the requirement/application flow forces to be called from a modal.

Absolutely no idea how to fix it. Need Help.

Thanks.

Unable to resolve module 'react-native-contacts-wrapper'

I have installed the library and I have linked it manually as it is written in the readme file but I am getting error when in the component I am writing this line
"import ContactsWrapper from 'react-native-contacts-wrapper'; "

iOS8.4 runtime error: no suitable image found.

Should this run ok in an iOS8.4 simulator? Am I missing some setup step? I'm getting:

dyld: Library not loaded: /System/Library/Frameworks/Contacts.framework/Contacts
  Referenced from: /Users/johnk/Library/Developer/CoreSimulator/Devices/1EE33EE4-FAEA-4E70-9838-F2CAB1854DE8/data/Containers/Bundle/Application/A84BD656-FFFB-48D1-91B3-908B1FE5B82B/My.app/MyApp
  Reason: no suitable image found.  Did find:
    /System/Library/Frameworks/Contacts.framework/Contacts: mach-o, but wrong architecture

It works fine in 9 and 10...

Update: Getting this on the react-native-contacts-wrapper-example project as well:

dyld: Library not loaded: /System/Library/Frameworks/ContactsUI.framework/ContactsUI
  Referenced from: /Users/johnk/Library/Developer/CoreSimulator/Devices/1EE33EE4-FAEA-4E70-9838-F2CAB1854DE8/data/Containers/Bundle/Application/345BAC00-1E17-404A-A37C-D77FC3FB58E3/RNContactsWrapperExample.app/RNContactsWrapperExample
  Reason: no suitable image found.  Did find:
    /System/Library/Frameworks/ContactsUI.framework/ContactsUI: mach-o, but wrong architecture

under iOS 8.4. So I'm guessing this approach won't work... :-\

Update#2: Ok, got it to work. Apparently both the Contacts and the ContactsUI libraries must be added to the project and marked as optional. This worked for both our project and the Example project cited above

Thanks

android compilation version sdk version too low

I have fixed it with: (26.0.1 is the sdk I have installed)

`sed -i -e 's/compileSdkVersion 23/compileSdkVersion 26/g' node_modules/react-native-contacts-wrapper/android/app/build.gradle
sed -i -e 's/23.0.1/26.0.1/g' node_modules/react-native-contacts-wrapper/android/app/build.gradle
sed -i -e 's/targetSdkVersion 23/targetSdkVersion 26/g' node_modules/react-native-contacts-wrapper/android/app/build.gradle

`

Problem with getContacts() callback

I am calling this function only once:

ContactsWrapper.getContact()
        .then((c) => {
          if(this.state.isEmail) this.emailSelected(c.email);
          else this.contactSelected(c.phone);
        })
        .catch((error) => {
          console.warn("ERROR CODE: "+ error.code);
          alert("Error: "+ error.message);
        });

RN 0.28 (Android)

screenshot_2016-09-17-20-18-59

import ContactsWrapper from 'react-native-contacts-wrapper';

I do a log on ContactsWrapper is undefined...even if I clearly have the package installed.
I can see this message in VS:

[ts]
Could not find a declaration file for module 'react-native-contacts-wrapper'. '/projects/prank/frontend/node_modules/react-native-contacts-wrapper/index.js' implicitly has an 'any' type.
  Try `npm install @types/react-native-contacts-wrapper` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-native-contacts-wrapper';` [7016]

any ideas?

Compile error on android

Hi all.

I have some error when install this component.
I have try in steps

  1. create new project
react-native init testcontact
cd testcontact
  1. install react-native-contacts-wrapper
    npm install react-native-contacts-wrapper --save

  2. link by manual, step bay step as https://github.com/LynxITDigital/react-native-contacts-wrapper

  3. run
    react-native run-android

and error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-contacts-wrapper:prepareComAndroidSupportAppcompatV72301Library'.
> Could not expand ZIP 'C:\Users\keyyu\AppData\Local\Android\sdk\extras\android\m2repository\com\android\support\appcompat-v7\23.0.1\appcompat-v7-23.0.1.aar'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

and run second time

C:\Users\keyyu\Atom\Workspace\testcontact\node_modules\react-native-contacts-wrapper\android\app\build\intermediates\res\merged\release\values\values.xml: Error: Failed to create directory: C:\Users\keyyu\Atom\Workspace\testcontact\node_modules\react-native-contacts-wrapper\android\app\build\intermediates\res\merged\release\values
:react-native-contacts-wrapper:mergeReleaseResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-contacts-wrapper:mergeReleaseResources'.
> C:\Users\keyyu\Atom\Workspace\testcontact\node_modules\react-native-contacts-wrapper\android\app\build\intermediates\res\merged\release\values\values.xml: Error: Failed to create directory: C:\Users\keyyu\Atom\Workspace\testcontact\node_modules\react-native-contacts-wrapper\android\app\build\intermediates\res\merged\release\values

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

my enviroment

"react": "15.4.2",
"react-native": "0.41.2",
"react-native-contacts-wrapper": "^0.2.3"

Can you help me. Thank you.

Anyway, you have some error on README file in manual android link. Wrong sign ' and `
capture

Get Address contact

It is possible to obtain the address of the selected contact, at this moment it only returns name, email and phone number

Npm package size is huge

Please publish new version where you removed build size. Size of the current version on npm is about 25 megabytes.

TypeError: null is not an object (evaluating '_reactNativeContactsWrapper.default.getContact') In IOS

Hi Guys,

I have faced below error on iOS. i am using react native 61 version.

Error: TypeError: null is not an object (evaluating '_reactNativeContactsWrapper.default.getContact')

It's working fine on Android but in iOS, it's showing error.

Below is my code:
ContactsWrapper.getContact()
.then((contact) => {
console.log("phone number",contact.phone);
// console.log("Contact List",contact);
this.setState({phone:contact.phone});
})
.catch((error) => {
console.log("ERROR CODE: ", error.code);
console.log("ERROR MESSAGE: ", error.message);
});

can you please me to resolve my issue for IOS?

Thanks

[ Question ] Is this easy to extend to get mailing address info from contact?

Thank you for sharing your work! I love how fast and responsive the picker is as tested in example under iOS! It seems perfect if you need a contact's phone or email.

I need cross-platform Android / iOS. I briefly looked at the iOS and Android native code.

Question: Would you expect this to be easy to extend to get the mailing address info for both Android and iOS contact? For iOS it looks like a matter of adding more addressbook keys.

Have any forks done this already?

I have stayed away from react-native-contacts because the readme indicated it was slow?

Compile error

Hi, I have installed the module, did rnpm link, everything good, but now my project cannot be compiled:

react-native-contacts-wrapper/android/app/src/main/java/com/lynxit/contactswrapper/ContactsWrapper.java:31: error: ContactsWrapper is not abstract and does not override abstract method onActivityResult(Activity,int,int,Intent) in ActivityEventListener
public class ContactsWrapper extends ReactContextBaseJavaModule implements ActivityEventListener {
       ^

and

react-native-contacts-wrapper/android/app/src/main/java/com/lynxit/contactswrapper/ContactsWrapper.java:80: error: method does not override or implement a method from a supertype
    @Override
    ^

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.