Contact syncing taking too much time


#1

I installed below plugin :-

ionic cordova plugin add cordova-plugin-contacts

npm install --save @ionic-native/contacts

But it is taking 1-2 minutes to fetch contacts in my ionic 3 app

and my app gets hang

please help me to reduce fetching time from device


#2

What is your ionic info output?
What is your code?
How are you building your app?
How many contacts does your testing device have?


#3

Hello, @Sujan12

Ionic Info:-

cli packages: 

    @ionic/cli-utils  : 1.19.2
    ionic (Ionic CLI) : 3.20.0

global packages:

    cordova (Cordova CLI) : 8.0.0

local packages:

    @ionic/app-scripts : 3.0.0
    Cordova Platforms  : android 6.3.0
    Ionic Framework    : ionic-angular 3.6.1

System:

    Android SDK Tools : 26.1.1
    Node              : v6.10.3
    npm               : 4.6.1
    OS                : Windows 7

Environment Variables:

    ANDROID_HOME : D:\Android\sdk

Misc:

    backend : pro

My code is:-

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams,LoadingController, AlertController,ToastController, ViewController } from 'ionic-angular';

import { DomSanitizer } from '@angular/platform-browser';

import { Http }  from '@angular/http';
import 'rxjs/Rx';
import 'rxjs/add/operator/map';

import { Network } from '@ionic-native/network';

import { Contact, ContactField, ContactName, Contacts } from '@ionic-native/contacts';

@IonicPage()
@Component
({
  selector: 'page-contact-demo',
  templateUrl: 'contact-demo.html',
})
export class ContactDemoPage 
{
    contactList = [];

    constructor(public navCtrl: NavController, public navParams: NavParams,public moduleService: ModuleProvider,public loadingCtrl: LoadingController,public toastCtrl: ToastController, private alertCtrl : AlertController,private network: Network, public view: ViewController,private contacts: Contacts, private sanitizer: DomSanitizer) 
    {
      
    }

    ionViewDidLoad() 
    {
      this.getContacts();
      console.log('ionViewDidLoad ContactDemoPage');
    }


    getContacts(): void 
    {
      this.contacts.find(
      ["displayName", "phoneNumbers"],
      {multiple: true, hasPhoneNumber: true}
      ).then((contacts) => 
      {
        for (var i=0 ; i < contacts.length; i++)
        {
          if(contacts[i].displayName !== null) 
          {
            var contact = {};
            contact["name"]   = contacts[i].displayName;
            contact["number"] = contacts[i].phoneNumbers[0].value;
            if(contacts[i].photos != null) 
            {
              console.log(contacts[i].photos);
              contact["image"] = this.sanitizer.bypassSecurityTrustUrl(contacts[i].photos[0].value);
              console.log(contact);
            } 
            else 
            {
              contact["image"] = "assets/icon/user.png";
            }
            this.contactList.push(contact);
          }
        }
      });

    }
}

I build by below command
Ionic cordova build android --prod

I have 500 contacts


#4

Your Cordova tooling seems to be out of date, which might be causing all kinds of problems.
You can read about how to figure out the current Cordova versions and how to update CLI, platforms and plugins here: https://ionic.zone/cordova/update

Also old. Using https://update.ionic.zone might help


#5

Hello, @Sujan12

yes after updating from given reference
i run npm install

and then when i build app

it throws some error

i tried your solution early morning


#6

Then post the updated ionic info, so we can confirm and exclude version problems as the cause.