【发布时间】:2016-06-26 19:39:25
【问题描述】:
因此,我正在构建一个应用程序,该应用程序从通讯录中获取联系信息并将其存储到 Titanium 模型中,以供以后在用户旅程中使用。
所有其他信息都在正确存储和返回,但是由于某种原因,联系人的图像总是空白。
保存通讯录信息的代码如下
if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_AUTHORIZED){
var people = Titanium.Contacts.getAllPeople();
var totalContacts = people.length;
var addressbook = [];
Alloy.Collections.contactsModel.numberOfContacts();
Ti.API.info(numberOfContacts);
if(totalContacts > 0){
var phoneContacts = [];
for (var index = 0; index < totalContacts; index++){
var person = people[index];
phoneContacts.push({
name:person.fullName,
phoneNumber:person.phone,
profileImage:person.image,
contactID:person.identifier
});
}
Alloy.Collections.contactsModel.reset(phoneContacts);
Alloy.Collections.contactsModel.each(function(_m) {
_m.save();
});
}
} else if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_UNKNOWN){
Ti.Contacts.requestAuthorization(function(e){
//Authorization is unknown so requesting for authorization
if (e.success) {
} else {
}
});
} else {
}
}
模型定义如下
exports.definition = {
config: {
columns: {
"friendID": "INTEGER PRIMARY KEY AUTOINCREMENT",
"contactID": "string",
"name": "string",
"phoneNumber": "string",
"emailAddress": "string",
"profileImage": "blob"
},
adapter: {
type: "sql",
collection_name: "contactsModel",
idAttribute:"friendID"
}
},
extendModel: function(Model) {
_.extend(Model.prototype, {
// extended functions and properties go here
});
return Model;
},
extendCollection: function(Collection) {
_.extend(Collection.prototype, {
collection.trigger('sync');
},
}
}
*/
});
return Collection;
}
};
从地址簿中收集图像并将其放入列表视图时,图像工作正常。但是,当它被保存后,我尝试检索它并将其放入出现问题的列表视图中。
谢谢大家。
【问题讨论】:
-
我刚刚发现这是因为图像无法保存到 SQLite DB 中。唯一的方法是将其转换为 base64 字符串或将其保存到空间,然后获取图像路径并存储它。一旦我完成了代码,我会发布它,这样每个人都可以看到我的方法以及我是如何解决它的。
标签: titanium titanium-mobile titanium-alloy appcelerator-titanium titanium-modules