If you use our user authentication mode and want to be sure that new users that have just logged in will have a different chat than previous users who has logged out, just use the login and logout methods.
Check the following examples to see how you can do it in your application:
Login example
ObjC:
- (IBAction)loginPressed:(id)sender {
HCSUser *user = [HCSUser new];
if ([self.nameTextField.text count] > 0) {
user.name = self.nameTextField.text;
}
if ([self.emailTextField.text count] > 0) {
user.email = self.emailTextField.text;
}
user.userId = self.userId;
[HelpCrunch updateUser:user completion:^(NSError * _Nullable error) {
// We're ready to log user in
}];
}
Swift:
@IBAction func buttonLoginPressed(_ sender: Any) {
let user = HCSUser()
user.userId = self.userId
if nameTextField.text.count > 0 {
user.name = nameTextField.text
}
if emailTextField.text.count > 0 {
user.email = emailTextField.text
}
HelpCrunch.update(user) { (error) in
// We're ready to log user in
}
}
Logout example:
ObjC:
- (IBAction)logout:(id)sender {
[HelpCrunch logoutWithCompletion:^(NSError * _Nullable error) {
// User successfully logged out
}];
}
Swift:
@IBAction func buttonLogoutPressed(_ sender: Any) {
HelpCrunch.logout { (error) in
// User successfully logged out
}
}