Maintain persistency of a logged in user

hey everyone
in swift am trying to get user persistency (avoid logging in every time app restarts ) well am able to get the current user with this codes :
func loginUserAsync() {

Email = userNameTextField.text!
Password = passwordTextField.text!

backendless.userService.login(
Email, password:Password,
response: { ( user : BackendlessUser!) -> () in

self.backendless.userService.setPersistentUser()
self.backendless.userService.setStayLoggedIn( true )

self.backendless.userService.getPersistentUser()

let user = self.backendless.userService.currentUser
if (user != nil) {
// get user’s email (i.e. mandatory/predefined property)
let userEmail = user.email
}
else if (user == nil) {
print(“User hasn’t been logged”)
}

},
error: { ( fault : Fault!) -> () in
print(“Server reported an error: (fault)”)
}
)
}

func validUserTokenAsync() {
    backendless.userService.isValidUserToken(
        { (var result : AnyObject!) -> () in
            print("isValidUserToken (ASYNC): \(result.boolValue)")
            
            
            let userToken = BackendlessUser.getUserToken(self.user)
            print("current user : \(self.backendless.userService.currentUser)")
            
            am getting current user while connected to internet
            
            
        },
        error: { (var fault : Fault!) -> () in
            print("Server reported an error (ASYNC): \(fault)")
        }
    )


















}

its working fine its giving me the current user even after restarting my app but my question is , how we get the current user when there’s no internet connection ? in documentation i wasn’t able to find anything related to my issue and am able to get current user without internet connection in (java ) android by using the user token but have no idea how to achieve this in iOS

thanks
Billion

Hi Billion,

What good is the user token, if there is no internet connection?

The user object per-se is not saved, only the user token and user id. On app restart, both values can be used to retrieve the actual user from the server, but you need to have the internet connection for that.

Mark

thanks mark

okay i’ll find a work around for logging in when there’s a connection available , but do java’s api and iOS’ api functionality haves difference between them ??

billion

They should not have any differences, however, if you notice different behavior, please let us know about it.