How to store and update a value that is persistent thruout the whole app?
Hi, I have this code, it opens a book when on one of the coords. However I need to be able to change a value for every point/book.
Opened, true or false, Based on whether it has already opened once.
I tried to update this value in the database, didn't work and I don't think it should based on how databases work in the iPhone? Any ideas?
Thanks
Titanium.Geolocation.addEventListener('location',function(e)
{
var longitude = e.coords.longitude;
var latitude = e.coords.latitude;
var db = Titanium.Database.open('sagobygden');
var rows = db.execute('SELECT * FROM s');
var dist;
var opened = 0;
while (rows.isValidRow()){
dist = Math.sqrt(Math.pow((111.3 * (latitude - rows.fieldByName('LAT'))),2) + Math.pow((71.5 * (longitude - rows.fieldByName('LONG'))),2)) * 1000;
if(dist<500 && !rows.fieldByName('opened')) {
openBook(rows.fieldByName('slug'));
db.execute('UPDATE s SET opened = ? WHERE ID = ?',1,rows.fieldByName('ID'));
}
rows.close();
});
3 Answers
-
I pass the data to each window and then retrieve it. It is a pain but works
\In the originating window var win1 = Titanium.UI.createWindow({ url:'main_windows/home.js', titleImage:'images/logo.png' }); win1.db = db; \in the new window var db = Ti.UI.currentWindow.db;
hope that helps
-
why not use the properties information?
Titanium.App.Properties.setString("variableName","variableProperty");
rocksteady,
danno~ -
Hey Danno, I thought about that, but what about an array? and I would need to reset that value everytime the app starts, right?