So baue ich eine Anwendung, die Kontaktinformationen aus dem Adressbuch und speichert es in einem Titanium-Modell für den späteren Gebrauch in der Benutzer-Reise.Store Adressbuch Kontakt in sqlite Titan
Alle anderen Informationen werden korrekt gespeichert und zurückgegeben, aber das Bild des Kontakts wird aus irgendeinem Grund immer leer angezeigt.
Der Code des Adressbuchs zum Speichern von Informationen ist als
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 {
}
}
Definition Das Modell folgt, ist wie folgt
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;
}
};
Das Bild fein gearbeitet, wenn es aus dem Adressbuch zu sammeln und sie setzen in eine Listenansicht. Wenn es jedoch gespeichert wird, und ich versuche, es abzurufen und es in einer List-Ansicht zu platzieren, in der das Problem auftritt.
Danke Jungs.
Ich habe gerade herausgefunden, dass ein Bild nicht in SQLite DB gespeichert werden kann. Die einzige Möglichkeit besteht darin, sie in eine Base64-Zeichenfolge umzuwandeln oder sie im Space zu speichern und dann den Image-Pfad zu erhalten und ihn stattdessen zu speichern. Sobald ich den Code ausgearbeitet habe, werde ich ihn veröffentlichen, so dass jeder meinen Ansatz sehen kann und wie ich ihn gelöst habe. –