I have updated “backendless.a” and “CommLibiOS.a” and now i am facing a weird problem. User registration works fine on first launch but after logging out, new user registration causes problem unless i kill the app and relaunch it.
Hi Waqar,
I cannot reproduce this issue.
I use the latest Backendless SDK release - CocoaPods (3.0.21) or current github.
Here my sample code (in swift, but it doesn’t matter):
class ViewController: UIViewController {
var backendless = Backendless.sharedInstance()
override func viewDidLoad() {
super.viewDidLoad()
registerUser("bob1@backendless.com", password: "bob1")
loginUser("bob1@backendless.com", password: "bob1")
print("FIRST USER: \(backendless.userService.currentUser.email)")
logoutUser()
registerUser("bob2@backendless.com", password: "bob2")
loginUser("bob2@backendless.com", password: "bob2")
print("SECOND USER: \(backendless.userService.currentUser.email)")
logoutUser()
}
func registerUser(email: String, password: String) {
Types.tryblock({ () -> Void in
let user = BackendlessUser()
user.email = email
user.password = password
self.backendless.userService.registering(user)
},
catchblock: { (exception) -> Void in
print("registerUser: server reported an error: \(exception as! Fault)")
}
)
}
func loginUser(email: String, password: String) {
Types.tryblock({ () -> Void in
let email = email
let password = password
self.backendless.userService.login(email, password: password)
},
catchblock: { (exception) -> Void in
print("loginUser: server reported an error: \(exception as! Fault)")
})
}
func logoutUser() {
Types.tryblock({ () -> Void in
self.backendless.userService.logout()
let user = self.backendless.userService.currentUser
print("User has been logged out (SYNC): \(user)")
},
catchblock: { (exception) -> Void in
print("logoutUser: server reported an error: \(exception as! Fault)")
})
}
}
Here is a log:
http://support.backendless.com/public/attachments/f1567e4db1c799768c18efd110be2924.png</img>
and result on app dashboard:
http://support.backendless.com/public/attachments/ccf623174ed44996f0a59debebe31f2a.png</img>
Could you reproduce your code and screenshots, which demonstrates this problem?
Regards,
Slava
Still same problem with latest libraries, this is how I am registering and loging out user
// method to register user
//user signup
-(void)signUpUser:(NSString *)username password:(NSString *)password
{
BackendlessUser *user = [BackendlessUser new];
user.name = username;
user.password = password;
NSLog(@"User name ; %@", user.name);
NSLog(@"User password ; %@", user.password);
[SVProgressHUD showWithStatus:@"Registering..."];
[backendless.userService registering:user response:^(BackendlessUser *user)
{
[SVProgressHUD showWithStatus:@"Logging in..."];
[backendless.userService login:username password:password response:^(BackendlessUser * user)
{
[backendless.userService setStayLoggedIn:YES];
if (backendless.userService.currentUser)
{
[self performSegueWithIdentifier:@“homeView” sender:self];
}
else
{
[SVProgressHUD showErrorWithStatus:@"Login Failed"];
NSLog(@"Login failed with Error: No user found");
}
}
error:^(Fault * error)
{
[SVProgressHUD showErrorWithStatus:@"Login Failed"];
NSLog(@"Login failed with Error %@", error);
}];
}error:^(Fault *error)
{
[SVProgressHUD showErrorWithStatus:@"Registration Failed"];
}];
}
// log out user
[backendless.userService logout:^(id response)
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
error:^(Fault *fault)
{
[SVProgressHUD showErrorWithStatus:@"Logout failed!"];
}];
// error log
2016-05-13 15:37:24.156 App[3548:1773488] User name ; (null)
2016-05-13 15:37:24.156 App[3548:1773488] User password ; (null)
Printing description of error:
FAULT = ‘3011’ [Property ‘password’ is required] <Property ‘password’ is required>
I am setting the username and password but user object says username and password is null and i have checked the values which i am passing to the register user method are not null.
I am setting the username and password but user object says username and password is null and i have checked the values which i am passing to the register user method are not null.
Are you saying NSLog has a bug in it? It prints null when the object is not null?
No, i didn’t say NSLog has bug in it, actually I am setting the username and password to the user object properties but right after assigning the values I am printing the values like user.username and user.password and it prints null for both and also server response says FAULT = ‘3011’ [Property ‘password’ is required] <Property ‘password’ is required>
Hi, Waqar,
First, to register an user you should set ‘email’ user property, not ‘name’.
Second, see to your code above:
BackendlessUser *user = [BackendlessUser new];
user.name = username;
user.password = password;
NSLog(@"User name ; %@", user.name);
NSLog(@"User password ; %@", user.password);
If log shown ‘null’, then the values of ‘username’ and ‘password’ variables are null, aren’t they? It is a problem of your code, not SDK.
I created sample project (see an attachment), please investigate TestCUserService target and try to follow its method implementations.
Regards,
Slava
TestUserService.zip (19.28MB)
‘username’ and ‘password’ variables are not null, i have checked it.