firescript / nativescript-contacts

A nativescript module that gives access to the native contact directory.
MIT License
28 stars 32 forks source link

getAllContacts only returns contacts the first time #83

Open fpaaske opened 4 years ago

fpaaske commented 4 years ago

After updating to NativeScript 6.5 and tns-android 6.5.0, getAllContacts(["name"]) only returns contacts the first time it's called.

I tested some older versions, and for NativeScript 6.5 and tns-android 6.4.0, the same code works well.

But for NativeScript 6.5 and tns-android 6.4.1 it fails again..

dlcole commented 4 years ago

Your issue prompted me to test my own app that uses getAllContacts. It works successfully on an Android emulator. Where were you seeing the problem?

tns doctor output:

✔ Component nativescript has 6.5.0 version and is up to date.
✔ Component tns-core-modules has 6.5.1 version and is up to date.
✔ Component tns-android has 6.5.0 version and is up to date.
✔ Component tns-ios has 6.5.0 version and is up to date.

BTW, I found an issue in the getContact method where the activityResult callback is called multiple times, once for each time getContact has been invoked. I have a local fix that removes the event listener upon completion and will be making a pull request. I looked at the getAllContacts method but this problem doesn't appear to exist there.

comporell commented 4 years ago

I have a local fix that removes the event listener upon completion and will be making a pull request.

Alternatively you can just unsubscribe the eventlistener then create a new event listener in case you don't have subscriptions.

this.contacts.contactsFound.unsubscribe(); this.contacts.contactsSaved = new EventEmitter<Object>();