PFUser

@interface PFUser : PFObject <PFSubclassing>

The PFUser class is a local representation of a user persisted to the Parse Data. This class is a subclass of a PFObject, and retains the same functionality of a PFObject, but also extends it with various user specific methods, like authentication, signing up, and validation uniqueness.

Many APIs responsible for linking a PFUser with Facebook or Twitter have been deprecated in favor of dedicated utilities for each social network. See PFFacebookUtils, PFTwitterUtils and PFAnonymousUtils for more information.

  • Gets the currently logged in user from disk and returns an instance of it.

    Declaration

    Objective-C

    + (nullable instancetype)currentUser;

    Return Value

    Returns a PFUser that is the currently logged in user. If there is none, returns nil.

  • The session token for the PFUser.

    This is set by the server upon successful authentication.

    Declaration

    Objective-C

    @property (readonly, copy, nonatomic, nullable) NSString *sessionToken;
  • Whether the PFUser was just created from a request.

    This is only set after a Facebook or Twitter login.

    Declaration

    Objective-C

    @property (readonly, assign, nonatomic) BOOL isNew;
  • Whether the user is an authenticated object for the device.

    An authenticated PFUser is one that is obtained via a -signUp: or +logInWithUsername:password: method. An authenticated object is required in order to save (with altered values) or delete it.

    Declaration

    Objective-C

    @property (readonly, getter=isAuthenticated, assign, nonatomic)
        BOOL authenticated;
  • Creates a new PFUser object.

    Declaration

    Objective-C

    + (nonnull instancetype)user;

    Return Value

    Returns a new PFUser object.

  • Enables automatic creation of anonymous users.

    After calling this method, +currentUser will always have a value. The user will only be created on the server once the user has been saved, or once an object with a relation to that user or an ACL that refers to the user has been saved.

    Warning

    PFObject.-saveEventually will not work on if an item being saved has a relation to an automatic user that has never been saved.

    Declaration

    Objective-C

    + (void)enableAutomaticUser;
  • The username for the PFUser.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) NSString *username;
  • ! The password for the PFUser.

    This will not be filled in from the server with the password. It is only meant to be set.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) NSString *password;
  • The email for the PFUser.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) NSString *email;
  • Signs up the user asynchronously.

    This will also enforce that the username isn’t already taken.

    Warning

    Make sure that password and username are set before calling this method.

    Declaration

    Objective-C

    - (id)signUpInBackground;

    Return Value

    The task, that encapsulates the work being done.

  • Signs up the user asynchronously.

    This will also enforce that the username isn’t already taken.

    Warning

    Make sure that password and username are set before calling this method.

    Declaration

    Objective-C

    - (void)signUpInBackgroundWithBlock:(nullable PFBooleanResultBlock)block;

    Parameters

    block

    The block to execute. It should have the following argument signature: ^(BOOL succeeded, NSError *error).

  • Makes an asynchronous request to login a user with specified credentials.

    Returns an instance of the successfully logged in PFUser. This also caches the user locally so that calls to +currentUser will use the latest logged in user.

    Declaration

    Objective-C

    + (id)logInWithUsernameInBackground:(nonnull NSString *)username
                               password:(nonnull NSString *)password;

    Parameters

    username

    The username of the user.

    password

    The password of the user.

    Return Value

    The task, that encapsulates the work being done.

  • Makes an asynchronous request to log in a user with specified credentials.

    Returns an instance of the successfully logged in PFUser. This also caches the user locally so that calls to +currentUser will use the latest logged in user.

    Declaration

    Objective-C

    + (void)logInWithUsernameInBackground:(nonnull NSString *)username
                                 password:(nonnull NSString *)password
                                    block:(nullable PFUserResultBlock)block;

    Parameters

    username

    The username of the user.

    password

    The password of the user.

    block

    The block to execute. It should have the following argument signature: ^(PFUser *user, NSError *error).

  • Makes an asynchronous request to become a user with the given session token.

    Returns an instance of the successfully logged in PFUser. This also caches the user locally so that calls to +currentUser will use the latest logged in user.

    Declaration

    Objective-C

    + (id)becomeInBackground:(nonnull NSString *)sessionToken;

    Parameters

    sessionToken

    The session token for the user.

    Return Value

    The task, that encapsulates the work being done.

  • Makes an asynchronous request to become a user with the given session token.

    Returns an instance of the successfully logged in PFUser. This also caches the user locally so that calls to +currentUser will use the latest logged in user.

    Declaration

    Objective-C

    + (void)becomeInBackground:(nonnull NSString *)sessionToken
                         block:(nullable PFUserResultBlock)block;

    Parameters

    sessionToken

    The session token for the user.

    block

    The block to execute. The block should have the following argument signature: ^(PFUser *user, NSError *error).

  • Enables revocable sessions and migrates the currentUser session token to use revocable session if needed.

    This method is required if you want to use PFSession APIs and your application’s ‘Require Revocable Session’ setting is turned off on http://parse.com app settings. After returned BFTask completes - PFSession class and APIs will be available for use.

    Declaration

    Objective-C

    + (id)enableRevocableSessionInBackground;

    Return Value

    An instance of BFTask that is completed when revocable sessions are enabled and currentUser token is migrated.

  • Enables revocable sessions and upgrades the currentUser session token to use revocable session if needed.

    This method is required if you want to use PFSession APIs and legacy sessions are enabled in your application settings on http://parse.com/. After returned BFTask completes - PFSession class and APIs will be available for use.

    Declaration

    Objective-C

    + (void)enableRevocableSessionInBackgroundWithBlock:
            (nullable PFUserSessionUpgradeResultBlock)block;

    Parameters

    block

    Block that will be called when revocable sessions are enabled and currentUser token is migrated.

  • Asynchronously logs out the currently logged in user.

    This will also remove the session from disk, log out of linked services and all future calls to +currentUser will return nil. This is preferrable to using -logOut, unless your code is already running from a background thread.

    Declaration

    Objective-C

    + (id)logOutInBackground;

    Return Value

    An instance of BFTask, that is resolved with nil result when logging out completes.

  • Asynchronously logs out the currently logged in user.

    This will also remove the session from disk, log out of linked services and all future calls to +currentUser will return nil. This is preferrable to using -logOut, unless your code is already running from a background thread.

    Declaration

    Objective-C

    + (void)logOutInBackgroundWithBlock:(nullable PFUserLogoutResultBlock)block;

    Parameters

    block

    A block that will be called when logging out completes or fails.

  • Send a password reset request asynchronously for a specified email and sets an error object. If a user account exists with that email, an email will be sent to that address with instructions on how to reset their password. - parameter: email Email of the account to send a reset password request. - returns: The task, that encapsulates the work being done.

    Declaration

    Objective-C

    + (id)requestPasswordResetForEmailInBackground:(nonnull NSString *)email;

    Parameters

    email

    Email of the account to send a reset password request.

    Return Value

    The task, that encapsulates the work being done.

  • Send a password reset request asynchronously for a specified email.

    If a user account exists with that email, an email will be sent to that address with instructions on how to reset their password.

    Declaration

    Objective-C

    + (void)requestPasswordResetForEmailInBackground:(nonnull NSString *)email
                                               block:(nullable PFBooleanResultBlock)
                                                         block;

    Parameters

    email

    Email of the account to send a reset password request.

    block

    The block to execute. It should have the following argument signature: ^(BOOL succeeded, NSError *error).

  • Registers a third party authentication delegate.

    Note

    This method shouldn’t be invoked directly unless developing a third party authentication library.

    See

    PFUserAuthenticationDelegate

    Declaration

    Objective-C

    + (void)registerAuthenticationDelegate:
                (nonnull id<PFUserAuthenticationDelegate>)delegate
                               forAuthType:(nonnull NSString *)authType;

    Parameters

    delegate

    The third party authenticaiton delegate to be registered.

    authType

    The name of the type of third party authentication source.

  • Logs in a user with third party authentication credentials.

    Note

    This method shouldn’t be invoked directly unless developing a third party authentication library.

    See

    PFUserAuthenticationDelegate

    Declaration

    Objective-C

    + (id)logInWithAuthTypeInBackground:(nonnull NSString *)authType
                               authData:
                                   (nonnull NSDictionary<NSString *, NSString *> *)
                                       authData;

    Parameters

    authType

    The name of the type of third party authentication source.

    authData

    The user credentials of the third party authentication source.

    Return Value

    A BFTask that is resolved to PFUser when logging in completes.

  • Links this user to a third party authentication library.

    Note

    This method shouldn’t be invoked directly unless developing a third party authentication library.

    See

    PFUserAuthenticationDelegate

    Declaration

    Objective-C

    - (id)linkWithAuthTypeInBackground:(nonnull NSString *)authType
                              authData:
                                  (nonnull NSDictionary<NSString *, NSString *> *)
                                      authData;

    Parameters

    authType

    The name of the type of third party authentication source.

    authData

    The user credentials of the third party authentication source.

    Return Value

    A BFTask that is resolved to @YES if linking succeeds.

  • Unlinks this user from a third party authentication library.

    Note

    This method shouldn’t be invoked directly unless developing a third party authentication library.

    See

    PFUserAuthenticationDelegate

    Declaration

    Objective-C

    - (id)unlinkWithAuthTypeInBackground:(nonnull NSString *)authType;

    Parameters

    authType

    The name of the type of third party authentication source.

    Return Value

    A BFTask that is resolved to @YES if unlinking succeeds.

  • Indicates whether this user is linked with a third party authentication library of a specific type.

    Note

    This method shouldn’t be invoked directly unless developing a third party authentication library.

    See

    PFUserAuthenticationDelegate

    Declaration

    Objective-C

    - (BOOL)isLinkedWithAuthType:(nonnull NSString *)authType;

    Parameters

    authType

    The name of the type of third party authentication source.

    Return Value

    YES if the user is linked with a provider, otherwise NO.