![](/img/trans.png)
[英]Titanium: Create fields like the ones in iPhone Contacts (Edit Mode) app
[英]Titanium_iphone contacts
我正在嘗試列出與Titanium的聯系。 在Android設備上運行,但在iPhone模擬器上未返回任何內容。
var contacts= Ti.Contacts.getAllPeople();
alert("contacts.length");
返回0。我不確定我在這里缺少什么。
確保在iOS模擬器上創建了聯系人:
同樣,在致電Ti.Contacts.getAllPeople()
之前,您還必須請求對聯系人列表的授權。 請嘗試以下代碼:
function processContacts() {
Ti.API.info('authorized');
var contacts = Ti.Contacts.getAllPeople();
Ti.API.info(contacts.length);
}
if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_AUTHORIZED){
processContacts();
} else if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_UNKNOWN){
Ti.Contacts.requestAuthorization(function(e){
if (e.success) {
processContacts();
} else {
Ti.API.info('disallowed');
}
});
} else {
Ti.API.info('disallowed');
}
最后一件事,在您的代碼中編寫了: alert("contacts.length")
,它將始終以“ contacts.length”為字符串而非值的形式顯示對話框視圖。 要正確調用它,您應該編寫: alert(contacts.length)
不帶雙引號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.