FBSDKProfile Class Reference
Inherits from | NSObject |
Conforms to | NSCopying NSSecureCoding |
Declared in | FBSDKProfile.h |
Overview
Represents an immutable Facebook profile
This class provides a global “currentProfile” instance to more easily add social context to your application. When the profile changes, a notification is posted so that you can update relevant parts of your UI and is persisted to NSUserDefaults.
Typically, you will want to call enableUpdatesOnAccessTokenChange:YES
so that
it automatically observes changes to the [FBSDKAccessToken currentAccessToken]
.
You can use this class to build your own FBSDKProfilePictureView
or in place of typical requests to “/me”.
Tasks
-
– initWithUserID:firstName:middleName:lastName:name:linkURL:refreshDate:
-
userID
property -
firstName
property -
middleName
property -
lastName
property -
name
property -
linkURL
property -
refreshDate
property -
+ currentProfile
-
+ setCurrentProfile:
-
+ enableUpdatesOnAccessTokenChange:
-
+ loadCurrentProfileWithCompletion:
-
– imageURLForPictureMode:size:
-
– imagePathForPictureMode:size:
-
– isEqualToProfile:
Properties
firstName
The user’s first name
@property (nonatomic, copy, readonly) NSString *firstName
Declared In
FBSDKProfile.h
lastName
The user’s last name
@property (nonatomic, copy, readonly) NSString *lastName
Declared In
FBSDKProfile.h
linkURL
A URL to the user’s profile.
@property (nonatomic, readonly) NSURL *linkURL
Discussion
Consider using Bolts and FBSDKAppLinkResolver
to resolve this
to an app link to link directly to the user’s profile in the Facebook app.
Declared In
FBSDKProfile.h
middleName
The user’s middle name
@property (nonatomic, copy, readonly) NSString *middleName
Declared In
FBSDKProfile.h
name
The user’s complete name
@property (nonatomic, copy, readonly) NSString *name
Declared In
FBSDKProfile.h
Class Methods
currentProfile
Gets the current FBSDKProfile instance.
+ (FBSDKProfile *)currentProfile
Declared In
FBSDKProfile.h
enableUpdatesOnAccessTokenChange:
Indicates if currentProfile
will automatically observe FBSDKAccessTokenDidChangeNotification
notifications
- Parameter enable: YES is observing
+ (void)enableUpdatesOnAccessTokenChange:(BOOL)enable
Discussion
If observing, this class will issue a graph request for public profile data when the current token’s userID
differs from the current profile. You can observe FBSDKProfileDidChangeNotification
for when the profile is updated.
Note that if [FBSDKAccessToken currentAccessToken]
is unset, the currentProfile
instance remains. It’s also possible
for currentProfile
to return nil until the data is fetched.
Declared In
FBSDKProfile.h
loadCurrentProfileWithCompletion:
Loads the current profile and passes it to the completion block. - Parameter completion: The block to be executed once the profile is loaded
+ (void)loadCurrentProfileWithCompletion:(void ( ^ ) ( FBSDKProfile *profile , NSError *error ))completion
Discussion
If the profile is already loaded, this method will call the completion block synchronously, otherwise it
will begin a graph request to update currentProfile
and then call the completion block when finished.
Declared In
FBSDKProfile.h
setCurrentProfile:
Sets the current instance and posts the appropriate notification if the profile parameter is different than the receiver. - Parameter profile: the profile to set
+ (void)setCurrentProfile:(FBSDKProfile *)profile
Discussion
This persists the profile to NSUserDefaults.
Declared In
FBSDKProfile.h
Instance Methods
imagePathForPictureMode:size:
A convenience method for returning a Graph API path for retrieving the user’s profile image.
- (NSString *)imagePathForPictureMode:(FBSDKProfilePictureMode)mode size:(CGSize)size
Discussion
- Warning:use
imageURLForPictureMode:size:
instead
You can pass this to a FBSDKGraphRequest
instance to download the image.
- Parameter mode: The picture mode
- Parameter size: The height and width. This will be rounded to integer precision.
Declared In
FBSDKProfile.h
imageURLForPictureMode:size:
A convenience method for returning a complete NSURL
for retrieving the user’s profile image.
- Parameter mode: The picture mode
- Parameter size: The height and width. This will be rounded to integer precision.
- (NSURL *)imageURLForPictureMode:(FBSDKProfilePictureMode)mode size:(CGSize)size
Declared In
FBSDKProfile.h
initWithUserID:firstName:middleName:lastName:name:linkURL:refreshDate:
initializes a new instance. - Parameter userID: the user ID - Parameter firstName: the user’s first name - Parameter middleName: the user’s middle name - Parameter lastName: the user’s last name - Parameter name: the user’s complete name - Parameter linkURL: the link for this profile - Parameter refreshDate: the optional date this profile was fetched. Defaults to [NSDate date].
- (instancetype)initWithUserID:(NSString *)userID firstName:(NSString *)firstName middleName:(NSString *)middleName lastName:(NSString *)lastName name:(NSString *)name linkURL:(NSURL *)linkURL refreshDate:(NSDate *)refreshDate
Declared In
FBSDKProfile.h