Cordova-Plugin-Contacts can't remove contact field

本秂侑毒 提交于 2019-12-10 18:26:31

问题


I'm retrieving all contacts from the system like this:

 navigator.contacts.find(["*"], function (contacts) {});

And then I pick one contact from the array (e.g. var myContact = contacts[4];). The contact has two or more phone number fields.

Shortened version of the contact's object:

{
    phoneNumbers: [
        {id: 0, type: "work", value: "123123123"},
        {id: 1, type: "home", value: "3216532425"}
    ]
}

When I remove one of the both contact fields from the phoneNumbers array and then save the contact, it still has both numbers on the device. When I re-retrieve the contact it has both numbers again. (Tested on iOS 9.3 with plugin version 2.0.1) I can't find any hint in the documentation if I do something wrong or if the plugin is behaving wrong.

I have created a demo script, which reproduces the issue. You can use it for testing: http://pastebin.com/XRdREL3Y

You might want to remove line 25 which removes the test contact in the end.

Shortened version of the demo script:

navigator.contacts.find(["*"], function (contacts) {
    // Pick a contact
    // (Make sure the contact has more than two phoneNumberFields)
    var myContact = contacts[4]; 

    // Remove the second phone number
    delete myContact.phoneNumbers[1];

    myContact.save(function () {
        console.log("Success");
        /// You will see, that the contact still has all it's previous phone numbers
    }, function () {
        console.error("error while saving");
    });

}, function () {
    console.error("Could not access conacts.");
});

So the question is: Does the plugin behave wrong? If not; how do you remove contact fields?

来源:https://stackoverflow.com/questions/36269632/cordova-plugin-contacts-cant-remove-contact-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!