Cordova-Plugin-Contacts无法删除联系人字段
我正在从系统中检索所有联系人,如下所示:
navigator.contacts.find(["*"], function (contacts) {});
然后我从数组中select一个联系人(例如var myContact = contacts[4];
)。 联系人有两个或更多电话号码字段。
联系人对象的缩短版本:
{ phoneNumbers: [ {id: 0, type: "work", value: "123123123"}, {id: 1, type: "home", value: "3216532425"} ] }
当我从phoneNumbers数组中删除两个联系人字段之一,然后保存联系人,它仍然有设备上的两个号码。 当我重新检索联系人时,它又有两个数字。 (使用插件版本2.0.1在iOS 9.3上testing)如果我做错了什么或者插件是否行为错误,我在文档中找不到任何提示。
我创build了一个演示脚本,它重现了这个问题。 您可以使用它进行testing: http : //pastebin.com/XRdREL3Y
您可能需要删除第25行,最后删除testing联系人。
演示脚本的缩短版本:
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."); });
所以问题是:插件的行为是否错误? 如果不; 你如何删除联系人字段?