![](/img/trans.png)
[英]cordova contacts plugin contact data is duplicating instead of overwriting contact data
[英]Cordova Contacts Plugin not always showing Contact List
我的應用程序和一個測試設備(iPhone 5,iOS 9.02)上有聯系人插件,聯系人列表沒有顯示。 當我進行搜索時,什么都沒有出現。 我沒有收到任何錯誤消息。 在我的一些其他設備上,如某些Android或iOS 8.x設備,它確實有效。 該特殊問題設備具有1200個觸點。 任何人都有一些關於如何修復的建議? 我將粘貼代碼的相關部分。 雖然可能更多的是配置問題?
$scope.getAllContacts = function(searchQuery) {
try {
var opts = { //search options
filter: searchQuery, // 'Bob'
multiple: true, // Yes, return any contact that matches criteria
fields: ['displayName', 'name']
};
if (ionic.Platform.isAndroid()) {
opts.hasPhoneNumber = true; //hasPhoneNumber only works for android.
};
$ionicLoading.show();
$cordovaContacts.find(opts).then(function(contactsFound) {
$scope.contacts = contactsFound;
$ionicLoading.hide();
});
} catch (err) {
alert(err.message);
}
};
$scope.getAllContacts("Ak");
嗨用這個來保存SD卡和顯示器中的所有聯系人。 (默認的Cordova聯系人和文件插件)
document.addEventListener("deviceReady", deviceReady, false);
function deviceReady() {
navigator.contacts.find(["*"], function(contacts) {
// alert("contacts.length = " + contacts.length);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getFile("contacts.json", {create: true, exclusive: false}, function(fileEntry) {
fileEntry.createWriter(function(writer) {
writer.onwriteend = function(){
// Success Contacts saved to sdcard as a contacts.json file
// Now get and read the json file
var path = fileSystem.root.getFile("contacts.json", {create:false},gotFileEntry, fail);
// jquery
$.getJSON(path, function (data) {
user = data;
$.each(user, function (index, user) {
var all_item = '<p id="'+user.id+'">'+user.displayName+'</p>';
$('#allcontacts').append(all_item);
});
});
};
writer.write(JSON.stringify(contacts));
}, onError);
}, onError);
}, onError);
}, onError,{"multiple": true});}
function onError(){
alert("Error");
}
您可以使用navigator.contacts.find,看看它是否適用於您的手機。 有關詳細信息, 請訪問https://github.com/apache/cordova-plugin-contacts
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.