如何使用PhoneGap的Andr​​oid中实现一次登录?如何使用、PhoneGap、oid、Andr

2023-09-08 09:29:18 作者:淡若轻风、静若繁华

我正在开发使用的PhoneGap为Android和iOS移动应用程序,我想实现像Gmail和Facebook应用程序登录模式即用户必须输入用户名和密码,只有在第一次,在此之后,应用程序应该自动登录只要应用程序starts.I我通过AJAX和jQuery这验证登录凭据调用Web服务。

I am developing a mobile application using Phonegap for android and ios, I want to implement login scheme like gmail and facebook application i.e. the user have to enter username and password only for the first time,after that the application should automatically log in as soon as the application starts.I am calling web services through ajax and jquery which validates the login credentials.

我看过很多帖子的iOS描述修改delegate.m文件,但对于Android的呢?

I have seen many posts for ios that describes to modify delegate.m file but what about android then?

推荐答案

您可以在storage.Check的持久型存储用户会话数据如果用户已经登录使用此数据。

You can store the user session data in a persistent form of storage.Check if a user has logged in using this data.

的http://docs.phonegap.com/en/2.1.0/cordova_storage_storage.md.html#localStorage

因此​​,步骤将是:

1。检查如果用户已登录使用存储在本地storage.You可以存储会话ID或布尔数据说isLoggedIn。

1.Check if a user has logged in using the data stored in local storage.You can either store the session id or a boolean say isLoggedIn.

2.如果会话ID为空或isLoggedIn布尔值false,present登录形式提供给用户。

2.If session id is null or isLoggedIn boolean false ,present the login form to the user.

3.Otherwise显示在主屏幕上。

3.Otherwise show the Home screen.

确认删除用户数据注销。

Make sure to delete data on user log out .