How to store UserID username in Titanium
Asked Answered
C

3

5

My app is similar to facebook. I want to retain the userID/Username upon login screen, so that i could use it at rest of the application for queries online data.

I tried storing it in a javascript object after successful login, but it gets washed away when i move to other screens.

Thanks

Copperas answered 18/6, 2011 at 11:53 Comment(0)
I
6

You can use the App.Properties API.

Example, right from the docs.

Titanium.App.Properties.setString("my_prop","cool");

Isopropyl answered 18/6, 2011 at 14:11 Comment(0)
P
2
if(Ti.Facebook.loggedIn) {
    if(Ti.App.Properties.hasProperty('fbid')) {
        var fbid = Ti.App.Properties.getString('fbid');
    }
}

You can use the hasProperty to verify they have logged in in the past and when they do logout you can use the removeProperty so that your app assumes they haven't logged in and starts over.

Photochemistry answered 18/6, 2011 at 14:12 Comment(0)
C
2

If you are going to store the information in the properties, you should be aware that the is information persisted on the device.

The use of properties for short term storage IMHO should be avoided if possible.

You have two choices, one store your variables in the Titanium namespace

Titanium.App.credentials = { "user" :"username", "pwd":"password123"};

Or create your own namespace and store your variable there. This will ensure you values are available throughout the application, but not stored on the device.

There is an example on my blog here http://blog.clearlyinnovative.com/post/6519148138/titanium-appcelerator-quickie-global-variables-scopes

Chromato answered 19/6, 2011 at 1:43 Comment(1)
That's what i have done eventually. Actually, i was referencing wrong object while retrieving, so i was getting wrong value. Thanks anyways.Copperas

© 2022 - 2024 — McMap. All rights reserved.