Hello 👋 How can we help?

Login/logout/user change methods

If you want to be sure that new registered users will have other chat than the previous ones, you can use the following methods.
Written by Konstantine
Updated 1 week ago

If you use user authentication mode and have a logout and you want to be sure, that new logged user will have other chat than the previous one, you can use login and logout method. Check this examples to see how you can do it in your application:

Login example

ObjC:
- (IBAction)loginPressed:(id)sender {
  NSMutableDictionary *userData = [[NSMutableDictionary alloc] init];

  if (![self fieldIsEmpty:self.nameTextField]) {
    [userData setValue:_nameTextField.text forKey:HC_UserNameAttributeName];
  }
  
  if (![self fieldIsEmpty:self.emailTextField]) {
    [userData setValue:_emailTextField.text forKey:HC_UserEmailAttributeName];
  }
  
  [userData setValue:self.userId forKey:HC_UserIdAttributeName];
  [HelpCrunch updateUser:userData completionHandler:^(BOOL succeeded, NSError *error) {
     // We're ready to log user in
  }];
}
Swift:
@IBAction func buttonLoginPressed(_ sender: Any) {
  var userData:[String: Any] = [HC_UserIdAttributeName:userId]

  if nameTextField.text.count > 0 {
    userData[HC_UserNameAttributeName] = nameTextField.text
  }
  
  if emailTextField.text.count > 0 {
    userData[HC_UserEmailAttributeName] = emailTextField.text
  }
  
  HelpCrunch.updateUser(userData) { (succeeded, error) in
     // We're ready to log user in
  }
}

Logout example:

ObjC:
- (IBAction)logout:(id)sender {
  [HelpCrunch logout:^(BOOL succeeded, NSError *error) {
    if (succeeded) {
      // User successfully logged out
    }
  }];
}
Swift:
@IBAction func buttonLogoutPressed(_ sender: Any) {
    HelpCrunch.logout { (succeeded, error) in
        // User successfully logged out
    }
}

 

Did this answer your question?