commit | author | age
|
2e29a3
|
1 |
/* |
L |
2 |
* Copyright (c) Meta Platforms, Inc. and affiliates. |
|
3 |
* All rights reserved. |
|
4 |
* |
|
5 |
* This source code is licensed under the license found in the |
|
6 |
* LICENSE file in the root directory of this source tree. |
|
7 |
*/ |
|
8 |
|
|
9 |
#if !TARGET_OS_TV |
|
10 |
|
|
11 |
#import <FBSDKCoreKit/FBSDKProfilePictureView.h> |
|
12 |
|
|
13 |
@class FBSDKLocation; |
|
14 |
@class FBSDKProfile; |
|
15 |
@class FBSDKUserAgeRange; |
|
16 |
|
|
17 |
NS_ASSUME_NONNULL_BEGIN |
|
18 |
|
|
19 |
/** |
|
20 |
Notification indicating that the `currentProfile` has changed. |
|
21 |
|
|
22 |
the userInfo dictionary of the notification will contain keys |
|
23 |
`FBSDKProfileChangeOldKey` and |
|
24 |
`FBSDKProfileChangeNewKey`. |
|
25 |
*/ |
|
26 |
FOUNDATION_EXPORT NSNotificationName const FBSDKProfileDidChangeNotification |
|
27 |
NS_SWIFT_NAME(ProfileDidChange); |
|
28 |
|
|
29 |
/* key in notification's userInfo object for getting the old profile. |
|
30 |
|
|
31 |
If there was no old profile, the key will not be present. |
|
32 |
*/ |
|
33 |
FOUNDATION_EXPORT NSString *const FBSDKProfileChangeOldKey |
|
34 |
NS_SWIFT_NAME(ProfileChangeOldKey); |
|
35 |
|
|
36 |
/* key in notification's userInfo object for getting the new profile. |
|
37 |
|
|
38 |
If there is no new profile, the key will not be present. |
|
39 |
*/ |
|
40 |
FOUNDATION_EXPORT NSString *const FBSDKProfileChangeNewKey |
|
41 |
NS_SWIFT_NAME(ProfileChangeNewKey); |
|
42 |
|
|
43 |
/** |
|
44 |
Describes the callback for loadCurrentProfileWithCompletion. |
|
45 |
@param profile the FBSDKProfile |
|
46 |
@param error the error during the request, if any |
|
47 |
|
|
48 |
*/ |
|
49 |
typedef void (^ FBSDKProfileBlock)(FBSDKProfile *_Nullable profile, NSError *_Nullable error) |
|
50 |
NS_SWIFT_NAME(ProfileBlock); |
|
51 |
|
|
52 |
/** |
|
53 |
Represents the unique identifier for an end user |
|
54 |
*/ |
|
55 |
typedef NSString FBSDKUserIdentifier |
|
56 |
NS_SWIFT_NAME(UserIdentifier); |
|
57 |
|
|
58 |
/** |
|
59 |
Represents an immutable Facebook profile |
|
60 |
|
|
61 |
This class provides a global "currentProfile" instance to more easily |
|
62 |
add social context to your application. When the profile changes, a notification is |
|
63 |
posted so that you can update relevant parts of your UI and is persisted to NSUserDefaults. |
|
64 |
|
|
65 |
Typically, you will want to call `enableUpdatesOnAccessTokenChange:YES` so that |
|
66 |
it automatically observes changes to the `[FBSDKAccessToken currentAccessToken]`. |
|
67 |
|
|
68 |
You can use this class to build your own `FBSDKProfilePictureView` or in place of typical requests to "/me". |
|
69 |
*/ |
|
70 |
NS_SWIFT_NAME(Profile) |
|
71 |
@interface FBSDKProfile : NSObject <NSCopying, NSSecureCoding> |
|
72 |
|
|
73 |
- (instancetype)init NS_UNAVAILABLE; |
|
74 |
+ (instancetype)new NS_UNAVAILABLE; |
|
75 |
|
|
76 |
/** |
|
77 |
initializes a new instance. |
|
78 |
@param userID the user ID |
|
79 |
@param firstName the user's first name |
|
80 |
@param middleName the user's middle name |
|
81 |
@param lastName the user's last name |
|
82 |
@param name the user's complete name |
|
83 |
@param linkURL the link for this profile |
|
84 |
@param refreshDate the optional date this profile was fetched. Defaults to [NSDate date]. |
|
85 |
*/ |
|
86 |
- (instancetype)initWithUserID:(FBSDKUserIdentifier *)userID |
|
87 |
firstName:(nullable NSString *)firstName |
|
88 |
middleName:(nullable NSString *)middleName |
|
89 |
lastName:(nullable NSString *)lastName |
|
90 |
name:(nullable NSString *)name |
|
91 |
linkURL:(nullable NSURL *)linkURL |
|
92 |
refreshDate:(nullable NSDate *)refreshDate; |
|
93 |
|
|
94 |
/** |
|
95 |
@param userID the user ID |
|
96 |
@param firstName the user's first name |
|
97 |
@param middleName the user's middle name |
|
98 |
@param lastName the user's last name |
|
99 |
@param name the user's complete name |
|
100 |
@param linkURL the link for this profile |
|
101 |
@param refreshDate the optional date this profile was fetched. Defaults to [NSDate date]. |
|
102 |
@param imageURL an optional URL to use for fetching a user's profile image |
|
103 |
@param email the user's email |
|
104 |
@param friendIDs a list of identifiers for the user's friends |
|
105 |
@param birthday the user's birthday |
|
106 |
@param ageRange the user's age range |
|
107 |
@param hometown the user's hometown |
|
108 |
@param location the user's location |
|
109 |
@param gender the user's gender |
|
110 |
@param isLimited indicates if the information provided is incomplete in some way. |
|
111 |
When true, `loadCurrentProfileWithCompletion:` will assume the profile is |
|
112 |
incomplete and disregard any cached profile. Defaults to false. |
|
113 |
*/ |
|
114 |
- (instancetype)initWithUserID:(FBSDKUserIdentifier *)userID |
|
115 |
firstName:(nullable NSString *)firstName |
|
116 |
middleName:(nullable NSString *)middleName |
|
117 |
lastName:(nullable NSString *)lastName |
|
118 |
name:(nullable NSString *)name |
|
119 |
linkURL:(nullable NSURL *)linkURL |
|
120 |
refreshDate:(nullable NSDate *)refreshDate |
|
121 |
imageURL:(nullable NSURL *)imageURL |
|
122 |
email:(nullable NSString *)email |
|
123 |
friendIDs:(nullable NSArray<FBSDKUserIdentifier *> *)friendIDs |
|
124 |
birthday:(nullable NSDate *)birthday |
|
125 |
ageRange:(nullable FBSDKUserAgeRange *)ageRange |
|
126 |
hometown:(nullable FBSDKLocation *)hometown |
|
127 |
location:(nullable FBSDKLocation *)location |
|
128 |
gender:(nullable NSString *)gender |
|
129 |
isLimited:(BOOL)isLimited; |
|
130 |
|
|
131 |
/** |
|
132 |
initializes a new instance. |
|
133 |
@param userID the user ID |
|
134 |
@param firstName the user's first name |
|
135 |
@param middleName the user's middle name |
|
136 |
@param lastName the user's last name |
|
137 |
@param name the user's complete name |
|
138 |
@param linkURL the link for this profile |
|
139 |
@param refreshDate the optional date this profile was fetched. Defaults to [NSDate date]. |
|
140 |
@param imageURL an optional URL to use for fetching a user's profile image |
|
141 |
@param email the user's email |
|
142 |
@param friendIDs a list of identifiers for the user's friends |
|
143 |
@param birthday the user's birthday |
|
144 |
@param ageRange the user's age range |
|
145 |
@param hometown the user's hometown |
|
146 |
@param location the user's location |
|
147 |
@param gender the user's gender |
|
148 |
*/ |
|
149 |
- (instancetype)initWithUserID:(FBSDKUserIdentifier *)userID |
|
150 |
firstName:(nullable NSString *)firstName |
|
151 |
middleName:(nullable NSString *)middleName |
|
152 |
lastName:(nullable NSString *)lastName |
|
153 |
name:(nullable NSString *)name |
|
154 |
linkURL:(nullable NSURL *)linkURL |
|
155 |
refreshDate:(nullable NSDate *)refreshDate |
|
156 |
imageURL:(nullable NSURL *)imageURL |
|
157 |
email:(nullable NSString *)email |
|
158 |
friendIDs:(nullable NSArray<FBSDKUserIdentifier *> *)friendIDs |
|
159 |
birthday:(nullable NSDate *)birthday |
|
160 |
ageRange:(nullable FBSDKUserAgeRange *)ageRange |
|
161 |
hometown:(nullable FBSDKLocation *)hometown |
|
162 |
location:(nullable FBSDKLocation *)location |
|
163 |
gender:(nullable NSString *)gender |
|
164 |
NS_DESIGNATED_INITIALIZER; |
|
165 |
|
|
166 |
/** |
|
167 |
The current profile instance and posts the appropriate notification |
|
168 |
if the profile parameter is different than the receiver. |
|
169 |
|
|
170 |
This persists the profile to NSUserDefaults. |
|
171 |
*/ |
|
172 |
|
|
173 |
/// The current profile |
|
174 |
@property (class, nullable, nonatomic, strong) FBSDKProfile *currentProfile |
|
175 |
NS_SWIFT_NAME(current); |
|
176 |
|
|
177 |
/** |
|
178 |
The user id |
|
179 |
*/ |
|
180 |
@property (nonatomic, readonly, copy) FBSDKUserIdentifier *userID; |
|
181 |
/** |
|
182 |
The user's first name |
|
183 |
*/ |
|
184 |
@property (nullable, nonatomic, readonly, copy) NSString *firstName; |
|
185 |
/** |
|
186 |
The user's middle name |
|
187 |
*/ |
|
188 |
@property (nullable, nonatomic, readonly, copy) NSString *middleName; |
|
189 |
/** |
|
190 |
The user's last name |
|
191 |
*/ |
|
192 |
@property (nullable, nonatomic, readonly, copy) NSString *lastName; |
|
193 |
/** |
|
194 |
The user's complete name |
|
195 |
*/ |
|
196 |
@property (nullable, nonatomic, readonly, copy) NSString *name; |
|
197 |
/** |
|
198 |
A URL to the user's profile. |
|
199 |
|
|
200 |
IMPORTANT: This field will only be populated if your user has granted your application the 'user_link' permission |
|
201 |
|
|
202 |
Consider using `FBSDKAppLinkResolver` to resolve this |
|
203 |
to an app link to link directly to the user's profile in the Facebook app. |
|
204 |
*/ |
|
205 |
@property (nullable, nonatomic, readonly) NSURL *linkURL; |
|
206 |
|
|
207 |
/** |
|
208 |
The last time the profile data was fetched. |
|
209 |
*/ |
|
210 |
@property (nonatomic, readonly) NSDate *refreshDate; |
|
211 |
/** |
|
212 |
A URL to use for fetching a user's profile image. |
|
213 |
*/ |
|
214 |
@property (nullable, nonatomic, readonly) NSURL *imageURL; |
|
215 |
/** |
|
216 |
The user's email. |
|
217 |
|
|
218 |
IMPORTANT: This field will only be populated if your user has granted your application the 'email' permission. |
|
219 |
*/ |
|
220 |
@property (nullable, nonatomic, readonly, copy) NSString *email; |
|
221 |
/** |
|
222 |
A list of identifiers of the user's friends. |
|
223 |
|
|
224 |
IMPORTANT: This field will only be populated if your user has granted your application the 'user_friends' permission. |
|
225 |
*/ |
|
226 |
@property (nullable, nonatomic, readonly, copy) NSArray<FBSDKUserIdentifier *> *friendIDs; |
|
227 |
|
|
228 |
/** |
|
229 |
The user's birthday. |
|
230 |
|
|
231 |
IMPORTANT: This field will only be populated if your user has granted your application the 'user_birthday' permission. |
|
232 |
*/ |
|
233 |
@property (nullable, nonatomic, readonly, copy) NSDate *birthday; |
|
234 |
|
|
235 |
/** |
|
236 |
The user's age range |
|
237 |
|
|
238 |
IMPORTANT: This field will only be populated if your user has granted your application the 'user_age_range' permission. |
|
239 |
*/ |
|
240 |
@property (nullable, nonatomic, readonly, copy) FBSDKUserAgeRange *ageRange; |
|
241 |
|
|
242 |
/** |
|
243 |
The user's hometown |
|
244 |
|
|
245 |
IMPORTANT: This field will only be populated if your user has granted your application the 'user_hometown' permission. |
|
246 |
*/ |
|
247 |
@property (nullable, nonatomic, readonly, copy) FBSDKLocation *hometown; |
|
248 |
|
|
249 |
/** |
|
250 |
The user's location |
|
251 |
|
|
252 |
IMPORTANT: This field will only be populated if your user has granted your application the 'user_location' permission. |
|
253 |
*/ |
|
254 |
@property (nullable, nonatomic, readonly, copy) FBSDKLocation *location; |
|
255 |
|
|
256 |
/** |
|
257 |
The user's gender |
|
258 |
|
|
259 |
IMPORTANT: This field will only be populated if your user has granted your application the 'user_gender' permission. |
|
260 |
*/ |
|
261 |
@property (nullable, nonatomic, readonly, copy) NSString *gender; |
|
262 |
|
|
263 |
/** |
|
264 |
Indicates if `currentProfile` will automatically observe `FBSDKAccessTokenDidChangeNotification` notifications |
|
265 |
@param enable YES is observing |
|
266 |
|
|
267 |
If observing, this class will issue a graph request for public profile data when the current token's userID |
|
268 |
differs from the current profile. You can observe `FBSDKProfileDidChangeNotification` for when the profile is updated. |
|
269 |
|
|
270 |
Note that if `[FBSDKAccessToken currentAccessToken]` is unset, the `currentProfile` instance remains. It's also possible |
|
271 |
for `currentProfile` to return nil until the data is fetched. |
|
272 |
*/ |
|
273 |
// UNCRUSTIFY_FORMAT_OFF |
|
274 |
+ (void)enableUpdatesOnAccessTokenChange:(BOOL)enable |
|
275 |
NS_SWIFT_NAME(enableUpdatesOnAccessTokenChange(_:)); |
|
276 |
// UNCRUSTIFY_FORMAT_ON |
|
277 |
|
|
278 |
/** |
|
279 |
Loads the current profile and passes it to the completion block. |
|
280 |
@param completion The block to be executed once the profile is loaded |
|
281 |
|
|
282 |
If the profile is already loaded, this method will call the completion block synchronously, otherwise it |
|
283 |
will begin a graph request to update `currentProfile` and then call the completion block when finished. |
|
284 |
*/ |
|
285 |
+ (void)loadCurrentProfileWithCompletion:(nullable FBSDKProfileBlock)completion; |
|
286 |
|
|
287 |
/** |
|
288 |
A convenience method for returning a complete `NSURL` for retrieving the user's profile image. |
|
289 |
@param mode The picture mode |
|
290 |
@param size The height and width. This will be rounded to integer precision. |
|
291 |
*/ |
|
292 |
// UNCRUSTIFY_FORMAT_OFF |
|
293 |
- (nullable NSURL *)imageURLForPictureMode:(FBSDKProfilePictureMode)mode size:(CGSize)size |
|
294 |
NS_SWIFT_NAME(imageURL(forMode:size:)); |
|
295 |
// UNCRUSTIFY_FORMAT_ON |
|
296 |
|
|
297 |
/** |
|
298 |
Returns YES if the profile is equivalent to the receiver. |
|
299 |
@param profile the profile to compare to. |
|
300 |
*/ |
|
301 |
- (BOOL)isEqualToProfile:(FBSDKProfile *)profile; |
|
302 |
@end |
|
303 |
|
|
304 |
NS_ASSUME_NONNULL_END |
|
305 |
|
|
306 |
#endif |