FBSDKProfile.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  2. //
  3. // You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
  4. // copy, modify, and distribute this software in source code or binary form for use
  5. // in connection with the web services and APIs provided by Facebook.
  6. //
  7. // As with any software that integrates with the Facebook platform, your use of
  8. // this software is subject to the Facebook Developer Principles and Policies
  9. // [http://developers.facebook.com/policy/]. This copyright notice shall be
  10. // included in all copies or substantial portions of the software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  14. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  15. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  16. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
  18. #import "FBSDKProfilePictureView.h"
  19. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  20. /**
  21. Notification indicating that the `currentProfile` has changed.
  22. the userInfo dictionary of the notification will contain keys
  23. `FBSDKProfileChangeOldKey` and
  24. `FBSDKProfileChangeNewKey`.
  25. */
  26. FOUNDATION_EXPORT NSNotificationName const FBSDKProfileDidChangeNotification;
  27. #else
  28. /**
  29. Notification indicating that the `currentProfile` has changed.
  30. the userInfo dictionary of the notification will contain keys
  31. `FBSDKProfileChangeOldKey` and
  32. `FBSDKProfileChangeNewKey`.
  33. */
  34. FOUNDATION_EXPORT NSString *const FBSDKProfileDidChangeNotification;
  35. #endif
  36. /* key in notification's userInfo object for getting the old profile.
  37. If there was no old profile, the key will not be present.
  38. */
  39. FOUNDATION_EXPORT NSString *const FBSDKProfileChangeOldKey;
  40. /* key in notification's userInfo object for getting the new profile.
  41. If there is no new profile, the key will not be present.
  42. */
  43. FOUNDATION_EXPORT NSString *const FBSDKProfileChangeNewKey;
  44. /**
  45. Represents an immutable Facebook profile
  46. This class provides a global "currentProfile" instance to more easily
  47. add social context to your application. When the profile changes, a notification is
  48. posted so that you can update relevant parts of your UI and is persisted to NSUserDefaults.
  49. Typically, you will want to call `enableUpdatesOnAccessTokenChange:YES` so that
  50. it automatically observes changes to the `[FBSDKAccessToken currentAccessToken]`.
  51. You can use this class to build your own `FBSDKProfilePictureView` or in place of typical requests to "/me".
  52. */
  53. @interface FBSDKProfile : NSObject<NSCopying, NSSecureCoding>
  54. - (instancetype)init NS_UNAVAILABLE;
  55. + (instancetype)new NS_UNAVAILABLE;
  56. /**
  57. initializes a new instance.
  58. @param userID the user ID
  59. @param firstName the user's first name
  60. @param middleName the user's middle name
  61. @param lastName the user's last name
  62. @param name the user's complete name
  63. @param linkURL the link for this profile
  64. @param refreshDate the optional date this profile was fetched. Defaults to [NSDate date].
  65. */
  66. - (instancetype)initWithUserID:(NSString *)userID
  67. firstName:(NSString *)firstName
  68. middleName:(NSString *)middleName
  69. lastName:(NSString *)lastName
  70. name:(NSString *)name
  71. linkURL:(NSURL *)linkURL
  72. refreshDate:(NSDate *)refreshDate NS_DESIGNATED_INITIALIZER;
  73. /**
  74. The user id
  75. */
  76. @property (nonatomic, copy, readonly) NSString *userID;
  77. /**
  78. The user's first name
  79. */
  80. @property (nonatomic, copy, readonly) NSString *firstName;
  81. /**
  82. The user's middle name
  83. */
  84. @property (nonatomic, copy, readonly) NSString *middleName;
  85. /**
  86. The user's last name
  87. */
  88. @property (nonatomic, copy, readonly) NSString *lastName;
  89. /**
  90. The user's complete name
  91. */
  92. @property (nonatomic, copy, readonly) NSString *name;
  93. /**
  94. A URL to the user's profile.
  95. Consider using Bolts and `FBSDKAppLinkResolver` to resolve this
  96. to an app link to link directly to the user's profile in the Facebook app.
  97. */
  98. @property (nonatomic, readonly) NSURL *linkURL;
  99. /**
  100. The last time the profile data was fetched.
  101. */
  102. @property (nonatomic, readonly) NSDate *refreshDate;
  103. /**
  104. Gets the current FBSDKProfile instance.
  105. */
  106. + (FBSDKProfile *)currentProfile;
  107. /**
  108. Sets the current instance and posts the appropriate notification if the profile parameter is different
  109. than the receiver.
  110. @param profile the profile to set
  111. This persists the profile to NSUserDefaults.
  112. */
  113. + (void)setCurrentProfile:(FBSDKProfile *)profile;
  114. /**
  115. Indicates if `currentProfile` will automatically observe `FBSDKAccessTokenDidChangeNotification` notifications
  116. @param enable YES is observing
  117. If observing, this class will issue a graph request for public profile data when the current token's userID
  118. differs from the current profile. You can observe `FBSDKProfileDidChangeNotification` for when the profile is updated.
  119. Note that if `[FBSDKAccessToken currentAccessToken]` is unset, the `currentProfile` instance remains. It's also possible
  120. for `currentProfile` to return nil until the data is fetched.
  121. */
  122. + (void)enableUpdatesOnAccessTokenChange:(BOOL)enable;
  123. /**
  124. Loads the current profile and passes it to the completion block.
  125. @param completion The block to be executed once the profile is loaded
  126. If the profile is already loaded, this method will call the completion block synchronously, otherwise it
  127. will begin a graph request to update `currentProfile` and then call the completion block when finished.
  128. */
  129. + (void)loadCurrentProfileWithCompletion:(void(^)(FBSDKProfile *profile, NSError *error))completion;
  130. /**
  131. A convenience method for returning a complete `NSURL` for retrieving the user's profile image.
  132. @param mode The picture mode
  133. @param size The height and width. This will be rounded to integer precision.
  134. */
  135. - (NSURL *)imageURLForPictureMode:(FBSDKProfilePictureMode)mode size:(CGSize)size;
  136. /**
  137. A convenience method for returning a Graph API path for retrieving the user's profile image.
  138. @warning use `imageURLForPictureMode:size:` instead
  139. You can pass this to a `FBSDKGraphRequest` instance to download the image.
  140. @param mode The picture mode
  141. @param size The height and width. This will be rounded to integer precision.
  142. */
  143. - (NSString *)imagePathForPictureMode:(FBSDKProfilePictureMode)mode size:(CGSize)size
  144. DEPRECATED_MSG_ATTRIBUTE("use imageURLForPictureMode:size: instead");
  145. /**
  146. Returns YES if the profile is equivalent to the receiver.
  147. @param profile the profile to compare to.
  148. */
  149. - (BOOL)isEqualToProfile:(FBSDKProfile *)profile;
  150. @end