Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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();
});
— asked May 22nd 2010 by Mattias Svedhem
  • annotations
  • iphone
  • mobile
  • persistent
  • value
0 Comments

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

    — answered May 22nd 2010 by Laney Dale
    permalink
    0 Comments
  • why not use the properties information?

    Titanium.App.Properties.setString("variableName","variableProperty");
    

    rocksteady,
    danno~

    — answered May 23rd 2010 by danno watts
    permalink
    0 Comments
  • Hey Danno, I thought about that, but what about an array? and I would need to reset that value everytime the app starts, right?

    — answered May 23rd 2010 by Mattias Svedhem
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.