How to store UserID username in Titanium

霸气de小男生 提交于 2019-12-04 07:00:38

You can use the App.Properties API.

Example, right from the docs.

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

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.

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!