I have a problem with Phonegap contacts.save. When I create a contact, it works fine on iOS and Android, but when I try to update a contact, there are duplicate files such as phoneNumbers, emails, URLs, ims, addresses, I use Phonegap 2.1 and Xcode 4.5.1.
Can someone help me solve this problem ?. I appreciate your time. Thanks.
In summary:
- navigator.contacts.create (); works correctly.
- when I try to update a contact, save it correctly, but add phone numbers instead.
My code is:
var options = new ContactFindOptions(); options.filter = 20; //just it an example. Looking for id 20. var fields = ['id']; var contact; navigator.contacts.find(fields,function(contacts){ if (contacts.length==0) contact = navigator.contacts.create(); else contact = contacts[0]; var tContactName = new ContactName(); tContactName.givenName = 'Name'; tContactName.LastName = 'LastName'; contact.name = tContactName; var tPhoneNumbers[2]; tPhoneNumbers[0] = new ContactField('work', '123456789012',true); tPhoneNumbers[1] = new ContactField('home', '120987654321', false); contact.phoneNumbers = tPhoneNumbers; contact.save(function(contact) { navigator.notification.alert('Saved sucessfully!!!',function(){},'Title'); }, function(contactError) { navigator.notification.alert('Error contact save: '+contactError.code,function(){},'Title'); } }, function(contactError) { navigator.notification.alert('Error contact find: '+contactError.code,function(){},'Title'); }, options);
source share