joshuapinter / react-native-unified-contacts

Your best friend when working with the latest and greatest Contacts Framework in iOS 9+ in React Native.
MIT License
158 stars 56 forks source link

Cannot read property 'getContacts' of undefined #30

Closed msutyak closed 6 years ago

msutyak commented 7 years ago

I'm using the following:

Contacts.getContacts( (error, contacts) => { if (error) { console.error(error); } else { console.log(contacts); } });

However, I am getting the error:

Cannot read property 'getContacts' of undefined

Why is this not working?

joshuapinter commented 7 years ago

This is because the library is not properly included. Did you follow the installation instructions to the letter?

Also, are you using the latest XCode and Swift? What versions?

How are you importing Contacts in your code?

msutyak commented 7 years ago

I followed the instructions to the letter. The one issue I have is I have another package (BVLinearGradient) that is preventing my project from compiling in XCode. However, it runs just fine in the simulator when using react-native run-ios from command line. My XCode is 8 and my Swift is 3.

joshuapinter commented 7 years ago

Hmm, take a look at https://github.com/joshuapinter/react-native-unified-contacts/issues/12 and see if anything in there is helpful.

Including a react-native library is painless when it's written in Objective-C but they still don't natively support Swift so we have to do a few more steps.

If you do find anything that helps, please post it back here or submit a PR to update the README with useful information.

xaxim commented 7 years ago

I had the same problem. Then I opened the project on Xcode 8.3.2 and upgraded the project to swift 3. Made the suggested changes (Just accepted whatever questions it threw at me) and then it worked.

joshuapinter commented 6 years ago

Just upgraded this to use Swift 4 and everything hums in XCode 9.2.

Closing this for now. Check out the latest version of the package 1.6.1 and let me know how it goes.

Thanks!

unutoiul commented 5 years ago

I'm using create-react-native-app...and i'm running the project from command line...

  1. do i need to run the project aswell from xcode to make the import? how?
  2. how can i import in my local without running xcode this is what reate-react-native-app says to use react-native link...but doesn't seams to work... any idea?
joshuapinter commented 5 years ago

@unutoiul I don't think this is the right issue to be posting this under.

But, try following the README.md first and see how things go. At the time of writing this library, react-native link did not support Swift libraries, which this is written in, so you need to link it manually.

unutoiul commented 5 years ago

how to do it manually... do I need to setup a xcode project? I don't use xcode I use the terminal and create-react-native-app