I am using below code to save contacts in device using phonegap. I want to perform certain action after all contacts saved successfully. But save() method is asynchronous so i can't able to know when all contacts are saved.
Is it possible without making change in save() method?
If not then, What changes are required in save() method?
for (var i = 0; i < allContacts.length; i++) {
var obj = eval(allContacts[i]);
var contact = navigator.contacts.create(obj);
contact.save();
}
Thanks in advance Yogesh Patel
I made change on above code
I have written code for restore multiple contacts in Iphone with Phonegap. And i want to perform certain action after all contacts restore successfull. Its working fine if no of contacts is near about 400 if i increase no of contacts near about 1000 then its skip some(10 to 15) of the contacts. Each time when i restore i get different no of skip contacts. And for the skip contacts fail() function is not called. What should i do next? I need to change save method in cordova js?
Below is my code:
function storeContacttodevice(json1,callback) {
var temp=0;
var json2 = json1.split(';');
for(var kl=0;kl<json2.length;kl++){
var jsonparsecontact=JSON.parse(json2[kl]);
var myContact = navigator.contacts.create(jsonparsecontact);
myContact.save(function onSuccess(contact){
var mssg="Restoring contacts to your device " + temp + " Out
Of " + json2.length;
$.mobile.showPageLoadingMsg( "b", mssg, false );
if(temp == json2.length - 1) {
return callback();
}
temp++;
} ,
function onError(contactError){
alert("Error in saving contacts");
return callback();
}
);
}
}
Thanks in advance Yogesh Patel