2

I have googled and tried to follow the solutions posted but did not come to a solution.

Does anyone have an idea why

 this.contacts.find(["name", "phoneNumbers"],
    {multiple: true, hasPhoneNumber: true}).then(
      (contacts) =>
      {
        this.contactList = contacts;


      }
    ).catch(err => {
      console.log('contacts error');
      console.log(err);
    });

is freezing my whole app? While the contacts are grabbed the gui does not respond anymore.

I am using : -

import { Contacts } from '@ionic-native/contacts/ngx';

but I could not solve the problem. I have about 2500 contacts on my iPhone. When using the code on simulator it is fine but simulator only has 6 contacts.

Log says 'Fetching in bulk 250 contacts!' plenty of time.

I'm really stuck and would be very happy if someone could give me a hint to solve this problem.

Best Regards

MohammedAli
  • 2,361
  • 2
  • 19
  • 36
svha
  • 41
  • 5

2 Answers2

0

This plugins requires the following usage description:

NSContactsUsageDescription describes the reason that the app accesses the user's contacts.

To add this entry into the info.plist, you can use the edit-config tag in the config.xml like this:

<edit-config target="NSContactsUsageDescription" file="*-Info.plist" mode="merge">
    <string>need contacts access to search friends</string>
</edit-config>
parrycima
  • 905
  • 8
  • 19
  • It‘s not config issue as with 6 contacts it works fine – svha Dec 21 '19 at 12:35
  • Does no one have a solution for that? – svha Jan 14 '20 at 12:38
  • Try to use this cordova plugin: https://github.com/dbaq/cordova-plugin-contacts-phone-numbers – parrycima Jan 14 '20 at 14:58
  • Hello parrycima. I've tried, but navigator.contactsPhoneNumbers.list returns null and I could find a solution for that. Do you have a link to a working example? I'm really stuck at this point...... – svha Jan 15 '20 at 14:09
  • 1
    Hello - FINALLY!!!! Fixed it according to this https://stackoverflow.com/questions/54647425/getting-count-of-contacts-correct-but-getting-null-values-for-contacts-in-ionic – svha Jan 15 '20 at 15:00
-1

Try to read only the data do you need. In desiredFields you can specify this camps. For example: Obtain only "name" and "phoneNumbers" of all information about each contact.

this.contacts.find(["name", "phoneNumbers"],
{multiple: true, hasPhoneNumber: true}, desiredFields: ['name','phoneNumbers']).then(
  (contacts) =>
  {
    this.contactList = contacts;


  }
).catch(err => {
  console.log('contacts error');
  console.log(err);
});