Results 1 to 10 of 10
  1.    #1  
    It appears that my app is not saving cookies. This only happen on the device though. On the emulator it works fine. Here is a short breakdown...

    1) I open the app and setup an account.

    2)The account data is stored in a global namespace and a cookie. While the app is running it uses the global namespace variables.

    3) I close/re-open the app. The cookie variables didn't save, so the app loads null values for the global namespace variables as it should if there is no account data in the cookies.

    Here are the functions I'm using to get/set cookie data. (NOTE: "MoJack is a global namespace that is setup in the app-assistant")...

    Code:
    // OPEN COOKIE
    // IF NEW, SET MOJACK GLOBALS TO NULL AND STORE COOKIE
    // OTHERWISE, SET MOJACK GLOBALS FROM COOKIE DATA
    
    	MoJack.cookie = new Mojo.Model.Cookie('com.mojackllc.mojack.cookie');
    
    	if (MoJack.cookie.get() == 'undefined' || MoJack.cookie.get() == '')
    	{
    		MoJack.account_id = null;
    		MoJack.email      = null;
    		MoJack.mode       = null;
    		MoJack.lastUpdate = null;
    
    		MoJack.storeCookie();
    	}
    	else
    	{
    		MoJack.account_id = MoJack.cookie.account_id;
    		MoJack.email      = MoJack.cookie.email;
    		MoJack.mode       = MoJack.cookie.mode;
    		MoJack.lastUpdate = MoJack.cookie.lastUpdate;
    	}
    
    // FUNCTION THAT STORES COOKIES
    
    	MoJack.storeCookie = function()
    	{
    		MoJack.cookie.put
    		({
    			cookieVersion: 1,
    			   account_id: MoJack.account_id,
    			           email: MoJack.email,
    			           mode: MoJack.mode,
    			    lastUpdate: MoJack.lastUpdate
    		});
    	};
    Like I said, this issue ONLY happens on my Pre. It works perfectly in the emulator. I THINK the issue might be in my "if" statement. Anyone see something in the code that could be preventing my cookie from saving correctly???
    MoBill - Use your Authorize.net account to bill your customers with your webOS device!!
    MoJack - Track your lost or stolen webOS device from anywhere!
    Time to get VIRAL
  2.    #2  
    EDIT: I removed this post. I thought I found a solution but it DID NOT work reliably!!!
    Last edited by Laxidasical; 12/07/2009 at 10:07 AM.
    MoBill - Use your Authorize.net account to bill your customers with your webOS device!!
    MoJack - Track your lost or stolen webOS device from anywhere!
    Time to get VIRAL
  3. #3  
    Fwiw, I found this approach to handling cookies in Palm's code:
    Code:
    v = cookie.get() || '';
    If the cookie is undefined, v gets assigned the empty string, which I can test in the next step.
  4. #4  
    Quote Originally Posted by samkim View Post
    Fwiw, I found this approach to handling cookies in Palm's code:
    Code:
    v = cookie.get() || '';
    If the cookie is undefined, v gets assigned the empty string, which I can test in the next step.
    agreed... i've had no issues doing it this way. null, undefined, etc. always scare me, and never seem to work or check out the way i think they should.
    My site: Shanerooni, LLC
    Follow me on Twitter
    My apps: GuessWhat? | MazeHunter3D | Small Wonders | PhakePhoney | AutismAware | PicSketcher | Cubix | QuickSolve | QuickSpell | QuickTrace | QuickWhack | QuickSuite | Soccer Shots | Ballooning |
    Cubix
  5.    #5  
    Ah, so you do something like...

    Code:
    cookie = new Mojo.Model.Cookie('someID');
    v = cookie.get() || '';
    
    if (v == '') {// COOKIE DOES NOT EXIST}
    else {// COOKIE EXISTS}
    One other thing. According to all the documentation I've read, doing it this way should allow you to access cookie variables by using whatever variable you set using the get() function, in this case "v", as such...

    Code:
    var firstName = v.firstName
    var lastName = v.lastName
    Yet, I can only seem to access them from the original cookie variable like this...

    Code:
    var firstName = cookie.firstName
    var lastName = cookie.lastName
    Which is correct???
    MoBill - Use your Authorize.net account to bill your customers with your webOS device!!
    MoJack - Track your lost or stolen webOS device from anywhere!
    Time to get VIRAL
  6. #6  
    What has always worked perfectly for me is

    if (MoJack.cookie)
    {
    MoJack.account_id = MoJack.cookie.account_id;
    MoJack.email = MoJack.cookie.email;
    MoJack.mode = MoJack.cookie.mode;
    MoJack.lastUpdate = MoJack.cookie.lastUpdate;
    }

    else
    .
    .
    .
    WOG Dev - WebOS Group http://www.WebOSGroup.com
    PMP Dev - http://www.PimpMyPre.com
    Apps: WOG O.S.K., WOG Card Keeper, WOG Glowstick, WOG Kid Protect, PreLoad, PimpMySounds
  7. #7  
    I didn't even know cookies could store objects. I had assumed they were limited to strings. Good to know.

    And Laxidasical, I'm glad you said that the solution from the second post didn't work - because it contradicted my understanding of javascript. I think that 'undefined' needs to be printed without quotes or else it'll be interpreted as a string. (I'm not absolutely certain about this, and if I'm wrong, someone please correct me.)
  8.    #8  
    Quote Originally Posted by samkim View Post
    I didn't even know cookies could store objects. I had assumed they were limited to strings. Good to know.

    And Laxidasical, I'm glad you said that the solution from the second post didn't work - because it contradicted my understanding of javascript. I think that 'undefined' needs to be printed without quotes or else it'll be interpreted as a string. (I'm not absolutely certain about this, and if I'm wrong, someone please correct me.)
    That was my thinking too, but I couldn't get "if (cookie === undefined)" to work at all. As a matter of fact, it stopped my app from loading (this code is in the initialization function of my app controller).

    At any rate, your way of testing if the cookie exists has been working perfectly!!!
    MoBill - Use your Authorize.net account to bill your customers with your webOS device!!
    MoJack - Track your lost or stolen webOS device from anywhere!
    Time to get VIRAL
  9. #9  
    Laxidasical, I doubt that this is your issue but I'll toss it out anyway. It looks like you are just trying to keep the users account & email address, a flag, and a date. Should be all short stuff. Is there any chance any of these are long strings? Real long - like a couple K? A cookie is supposed to hold 4K, but I've had problems with them doing so reliably. I had to break my stuff into multiple cookies of about 2.5K or 3K each. No one on the Palm forum has ever responded to my query into this.

    The other thing I noticed is your cookie naming - com.mojackllc.mojack.cookie. I just named mine with a single word. Using your example, cookie. WebOS does the work of keeping your cookies separate from everyone else's. You don't need to prepend with your appid. Maybe the real Pre is getting confused with the cookie id?

    Last note - is your emulator up to date? Perhaps your pre is far enough ahead of the emulator that something is different. (although if this is the issue, it means your emulator update might break it in the emulator)
  10.    #10  
    Hello Ken,

    Thanks for the post, great troubleshooting ideas...

    The account_id is being passed from my website (which is currently 3 digits long). The mode is a single digit as is the cookieVersion. The longest variables are lastUpdate (ie. 12/09/2009 2:30 PM) and email. This should be well under 4K.

    The cookie name had crossed my mind as well. I changed it in between the time of my first post and the solution that samkim posted. After applying his changes I went back to the original cookie name just to see what would happen. Everything seemed to work correctly with it, but I went with a one word cookie still.

    I always update my emulator to whatever version my Pre is running (currently 1.3.1). So far, cookies are the only thing I've found that seems to run differently. The exact same code will run fine on the emulator, but breaks on the Pre. I get it working on the Pre, but then it breaks in the emulator. The way I'm doing it now works in both:

    Code:
    // OPEN COOKIE
    // IF NEW, SET MOJACK VALUES TO NULL
    // OTHERWISE, SET MOJACK GLOBALS FROM COOKIE DATA
    
    	MoJack.cookie = new Mojo.Model.Cookie('MoJackCookie');
    	cookieData = MoJack.cookie.get() || '';
    
    	if (cookieData == '')
    	{
    		MoJack.account_id = null;
    			 MoJack.email = null;
    			  MoJack.mode = null;
    		MoJack.lastUpdate = null;
    	}
    	else
    	{
    		MoJack.account_id = cookieData.account_id;
    			 MoJack.email = cookieData.email;
    			  MoJack.mode = cookieData.mode;
    		MoJack.lastUpdate = cookieData.lastUpdate;
    	}
    MoBill - Use your Authorize.net account to bill your customers with your webOS device!!
    MoJack - Track your lost or stolen webOS device from anywhere!
    Time to get VIRAL

Posting Permissions