morenoh149 / react-native-contacts

React Native Contacts
MIT License
1.65k stars 564 forks source link

Android error: Contacts.getAll got 3 arguments, expected 2 #583

Closed nnslvp closed 3 years ago

nnslvp commented 3 years ago

Version: 6.0.3

Code:

return PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
      {
        'title': 'Contacts',
        'message': 'This app would like to view your contacts.',
        'buttonPositive': 'Allow'
      }
    )
      .then(Contacts.getAll);

Error on running com.facebook.react.bridge.NativeArgumentsParseException: Contacts.getAll got 3 arguments, expected 2

image
morenoh149 commented 3 years ago

does the example throw the same error? https://github.com/morenoh149/react-native-contacts/tree/master/example

Biciato commented 3 years ago

does the example throw the same error? https://github.com/morenoh149/react-native-contacts/tree/master/example

which example ?

Biciato commented 3 years ago

Version: 6.0.3

Code:

return PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
      {
        'title': 'Contacts',
        'message': 'This app would like to view your contacts.',
        'buttonPositive': 'Allow'
      }
    )
      .then(Contacts.getAll);

Error on running com.facebook.react.bridge.NativeArgumentsParseException: Contacts.getAll got 3 arguments, expected 2

image

change .then(Contacts.getAll); by .then(() => Contacts.getAll()); solves for me

morenoh149 commented 3 years ago

very odd, feels like getAll is getting 3 args but it only needs 2. Shouldn't javascript ignore the third arg? maybe its the native bridge that can't ignore the third arg.

Biciato commented 3 years ago

very odd, feels like getAll is getting 3 args but it only needs 2. Shouldn't javascript ignore the third arg? maybe its the native bridge that can't ignore the third arg.

It's the Java part that complains, not javascript, i believe

SalvaHasan commented 3 years ago

The following changes fixed this issue for me, write await before Contacts.getAll and change this to: Contacts.getAll to await Contact.getAll()

morenoh149 commented 3 years ago

@SalvaHasan that looks right. The current api is async.

ibelgin commented 3 years ago

.then(() => Contacts.getAll());

I tried this but my app closes when i run that

morenoh149 commented 3 years ago

@ibelgin need more code. Did you try?

.then(async () => {
  await Contacts.getAll();
 });