Deleting a User

Sometimes users wish to remove themselves from your application and you might want to permanently delete their accounts.

To delete the currently logged-in user, please execute the delete method.

Swift 3:

  • // Get the currently logged-in user.
    let user = KiiUser.current()!
    
    do{
      // Delete the user.
      try user.deleteSynchronous()
    } catch let error as NSError {
      // Handle the error.
      return
    }
  • // Get the currently logged-in user.
    let user = KiiUser.current()!
    
    // Delete the user.
    user.delete { (user :KiiUser?, error : Error?) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    }

Objective-C:

  • NSError *error;
    
    // Get the currently logged-in user.
    KiiUser *user = [KiiUser currentUser];
    
    // Delete the user.
    [user deleteSynchronous:&error];
    if (error != nil) {
      // Handle the error.
      return;
    }
  • // Get the currently logged-in user.
    KiiUser *user = [KiiUser currentUser];
    
    // Delete the user.
    [user deleteWithBlock:^(KiiUser *user, NSError *error) {
      if (error != nil) {
        // Handle the error.
        return;
      }
    }];

When a user is deleted, all data that belong to this user (i.e. buckets, KiiObjects, topics, and device installation) will be automatically deleted.

Note that a group and its data (i.e. buckets, KiiObjects, and topics) will not be deleted even if the group owner or the last group member is deleted.

The users can only delete themselves. A group owner cannot delete the group members.

If the user deletion succeeds, the login state is cancelled and the user is treated as an anonymous user.

You can also delete pseudo users by executing the method while they are logged in with their access tokens.