GithubHelp home page GithubHelp logo

Comments (7)

Elyft avatar Elyft commented on August 25, 2024 1

thank you for your snippet, but i'm not sure that it can fit yo my need let me show you my code

module.exports = (...arrayToSearch)=>{
    return new Promise((resolve)=>{
        function getNameWithNumber(value){
            return new Promise((resolve)=>{
                function onSuccess(contacts) {
                    console.log(value)
                    resolve(contacts);
                };

                function onError(contactError) {
                    console.log(contactError)
                };

                const options = new ContactFindOptions();
                options.filter = value.address;
                options.multiple = true;
                options.hasPhoneNumber = true;
                const fields = ["*"];
                navigator.contacts.find(fields, onSuccess, onError, options);
                
            });
        }

        function getAllNames(...arrayToSearch){
          return Promise.all(arrayToSearch.map(getNameWithNumber)).then((value)=>{
           console.log(value)
          });
        }
        getAllNames(...arrayToSearch);
    });
};

Where arrayToSearch is an array of numbers to search

from cordova-plugin-contacts.

acedigibits avatar acedigibits commented on August 25, 2024

@Elyft it is because the process is asynchronous. i tried the same with for loop and failed. instead of for loop i looped it back to original function onsuccess with a global counter in the original main loop function. This gave complete result.

Hope this answers your query.

from cordova-plugin-contacts.

Elyft avatar Elyft commented on August 25, 2024

@acedigibits i don't really understand what you say. can you please give me a little snippet?thank you

from cordova-plugin-contacts.

acedigibits avatar acedigibits commented on August 25, 2024

var main_counter=0, global_data;
function main_loop(){
if(main_counter<5){
contact.find(,onsuccess, onerror);
}else{
//your complete data
}
}
function onsuccess(){
main_counter++;
//global_data merge
main_loop();
}

from cordova-plugin-contacts.

acedigibits avatar acedigibits commented on August 25, 2024

`module.exports = (...arrayToSearch)=>{
return new Promise((resolve)=>{
let main_counter=0, contacts_merge=[];
function getNameWithNumber(value){
return new Promise((resolve)=>{
function onSuccess(contacts) {
console.log(value);
if(main_counter>=5)
resolve(contacts);
else{
main_counter++;
contacts_merge.push(contacts);
main_loop();
}
};

            function onError(contactError) {
                console.log(contactError)
            };
			
			function main_loop(){
				const options = new ContactFindOptions();
            options.filter = value.address;
            options.multiple = true;
            options.hasPhoneNumber = true;
            const fields = ["*"];
            navigator.contacts.find(fields, onSuccess, onError, options);
			}

            main_loop();
            
        });
    }

    function getAllNames(...arrayToSearch){
      return Promise.all(arrayToSearch.map(getNameWithNumber)).then((value)=>{
       console.log(value)
      });
    }
    getAllNames(...arrayToSearch);
});

};`

from cordova-plugin-contacts.

acedigibits avatar acedigibits commented on August 25, 2024

you can check my app, where i have written loop and shown loading bar to indicate progress...

https://play.google.com/store/apps/details?id=com.acedb.bulkcontactcreate

from cordova-plugin-contacts.

timbru31 avatar timbru31 commented on August 25, 2024

We are archiving this repository following Apache Cordova's Deprecation Policy. We will not continue to work on this repository. Therefore all issues and pull requests are being closed. Thanks for your contribution.

from cordova-plugin-contacts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.