Cordova-Plugin-Contacts无法删除联系人字段

时间:2016-03-28 19:29:19

标签: ios cordova cordova-plugins contacts

我正在从系统中检索所有联系人:

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

然后我从数组中选择一个联系人(例如var myContact = contacts[4];)。该联系人有两个或更多电话号码字段。

联系人对象的缩短版本:

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

当我从phoneNumbers阵列中删除其中一个联系人字段然后保存该联系人时,它仍然在设备上同时包含两个号码。当我重新检索联系人时,它再次有两个号码。 (在iOS 9.3上使用插件版本2.0.1测试) 如果我做错了或者插件表现不对,我在文档中找不到任何提示。

我创建了一个演示脚本,可以重现该问题。您可以使用它进行测试: http://pastebin.com/XRdREL3Y

您可能希望删除最后删除测试联系人的第25行。

演示脚本的缩短版本:

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.");
});

所以问题是:插件是否表现错误?如果不;如何删除联系人字段?

0 个答案:

没有答案
相关问题