commit | author | age
|
bad748
|
1 |
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved. |
W |
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 |
13e53a
|
17 |
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE." |
bad748
|
18 |
|
49b883
|
19 |
#import "TargetConditionals.h" |
L |
20 |
|
|
21 |
#if !TARGET_OS_TV |
|
22 |
|
bad748
|
23 |
#import "FBSDKProfilePictureView.h" |
13e53a
|
24 |
|
e81c27
|
25 |
@class FBSDKProfile; |
H |
26 |
|
|
27 |
NS_ASSUME_NONNULL_BEGIN |
|
28 |
|
13e53a
|
29 |
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 |
bad748
|
30 |
|
9febd9
|
31 |
/** |
W |
32 |
Notification indicating that the `currentProfile` has changed. |
|
33 |
|
|
34 |
the userInfo dictionary of the notification will contain keys |
bad748
|
35 |
`FBSDKProfileChangeOldKey` and |
W |
36 |
`FBSDKProfileChangeNewKey`. |
|
37 |
*/ |
e81c27
|
38 |
FOUNDATION_EXPORT NSNotificationName const FBSDKProfileDidChangeNotification |
H |
39 |
NS_SWIFT_NAME(ProfileDidChange); |
13e53a
|
40 |
|
H |
41 |
#else |
|
42 |
|
|
43 |
/** |
e81c27
|
44 |
Notification indicating that the `currentProfile` has changed. |
13e53a
|
45 |
|
H |
46 |
the userInfo dictionary of the notification will contain keys |
|
47 |
`FBSDKProfileChangeOldKey` and |
|
48 |
`FBSDKProfileChangeNewKey`. |
|
49 |
*/ |
e81c27
|
50 |
FOUNDATION_EXPORT NSString *const FBSDKProfileDidChangeNotification |
H |
51 |
NS_SWIFT_NAME(ProfileDidChangeNotification); |
13e53a
|
52 |
|
H |
53 |
#endif |
bad748
|
54 |
|
9febd9
|
55 |
/* key in notification's userInfo object for getting the old profile. |
W |
56 |
|
|
57 |
If there was no old profile, the key will not be present. |
bad748
|
58 |
*/ |
e81c27
|
59 |
FOUNDATION_EXPORT NSString *const FBSDKProfileChangeOldKey |
H |
60 |
NS_SWIFT_NAME(ProfileChangeOldKey); |
bad748
|
61 |
|
9febd9
|
62 |
/* key in notification's userInfo object for getting the new profile. |
W |
63 |
|
|
64 |
If there is no new profile, the key will not be present. |
bad748
|
65 |
*/ |
e81c27
|
66 |
FOUNDATION_EXPORT NSString *const FBSDKProfileChangeNewKey |
H |
67 |
NS_SWIFT_NAME(ProfileChangeNewKey); |
|
68 |
|
|
69 |
/** |
|
70 |
Describes the callback for loadCurrentProfileWithCompletion. |
|
71 |
@param profile the FBSDKProfile |
|
72 |
@param error the error during the request, if any |
|
73 |
|
|
74 |
*/ |
|
75 |
typedef void (^FBSDKProfileBlock)(FBSDKProfile *_Nullable profile, NSError *_Nullable error) |
|
76 |
NS_SWIFT_NAME(ProfileBlock); |
bad748
|
77 |
|
9febd9
|
78 |
/** |
W |
79 |
Represents an immutable Facebook profile |
|
80 |
|
|
81 |
This class provides a global "currentProfile" instance to more easily |
bad748
|
82 |
add social context to your application. When the profile changes, a notification is |
W |
83 |
posted so that you can update relevant parts of your UI and is persisted to NSUserDefaults. |
|
84 |
|
|
85 |
Typically, you will want to call `enableUpdatesOnAccessTokenChange:YES` so that |
|
86 |
it automatically observes changes to the `[FBSDKAccessToken currentAccessToken]`. |
|
87 |
|
|
88 |
You can use this class to build your own `FBSDKProfilePictureView` or in place of typical requests to "/me". |
|
89 |
*/ |
e81c27
|
90 |
NS_SWIFT_NAME(Profile) |
bad748
|
91 |
@interface FBSDKProfile : NSObject<NSCopying, NSSecureCoding> |
W |
92 |
|
13e53a
|
93 |
- (instancetype)init NS_UNAVAILABLE; |
H |
94 |
+ (instancetype)new NS_UNAVAILABLE; |
|
95 |
|
9febd9
|
96 |
/** |
W |
97 |
initializes a new instance. |
13e53a
|
98 |
@param userID the user ID |
H |
99 |
@param firstName the user's first name |
|
100 |
@param middleName the user's middle name |
|
101 |
@param lastName the user's last name |
|
102 |
@param name the user's complete name |
|
103 |
@param linkURL the link for this profile |
|
104 |
@param refreshDate the optional date this profile was fetched. Defaults to [NSDate date]. |
bad748
|
105 |
*/ |
W |
106 |
- (instancetype)initWithUserID:(NSString *)userID |
e81c27
|
107 |
firstName:(nullable NSString *)firstName |
H |
108 |
middleName:(nullable NSString *)middleName |
|
109 |
lastName:(nullable NSString *)lastName |
|
110 |
name:(nullable NSString *)name |
|
111 |
linkURL:(nullable NSURL *)linkURL |
|
112 |
refreshDate:(nullable NSDate *)refreshDate NS_DESIGNATED_INITIALIZER; |
|
113 |
|
|
114 |
/** |
|
115 |
The current profile instance and posts the appropriate notification |
|
116 |
if the profile parameter is different than the receiver. |
|
117 |
|
|
118 |
This persists the profile to NSUserDefaults. |
|
119 |
*/ |
|
120 |
|
|
121 |
/// The current profile |
|
122 |
@property (class, nonatomic, strong, nullable) FBSDKProfile *currentProfile |
|
123 |
NS_SWIFT_NAME(current); |
|
124 |
|
9febd9
|
125 |
/** |
W |
126 |
The user id |
bad748
|
127 |
*/ |
9febd9
|
128 |
@property (nonatomic, copy, readonly) NSString *userID; |
W |
129 |
/** |
|
130 |
The user's first name |
bad748
|
131 |
*/ |
e81c27
|
132 |
@property (nonatomic, copy, readonly, nullable) NSString *firstName; |
9febd9
|
133 |
/** |
W |
134 |
The user's middle name |
bad748
|
135 |
*/ |
e81c27
|
136 |
@property (nonatomic, copy, readonly, nullable) NSString *middleName; |
9febd9
|
137 |
/** |
W |
138 |
The user's last name |
bad748
|
139 |
*/ |
e81c27
|
140 |
@property (nonatomic, copy, readonly, nullable) NSString *lastName; |
9febd9
|
141 |
/** |
W |
142 |
The user's complete name |
bad748
|
143 |
*/ |
e81c27
|
144 |
@property (nonatomic, copy, readonly, nullable) NSString *name; |
9febd9
|
145 |
/** |
W |
146 |
A URL to the user's profile. |
|
147 |
|
e81c27
|
148 |
Consider using `FBSDKAppLinkResolver` to resolve this |
bad748
|
149 |
to an app link to link directly to the user's profile in the Facebook app. |
W |
150 |
*/ |
e81c27
|
151 |
@property (nonatomic, readonly, nullable) NSURL *linkURL; |
bad748
|
152 |
|
9febd9
|
153 |
/** |
W |
154 |
The last time the profile data was fetched. |
bad748
|
155 |
*/ |
W |
156 |
@property (nonatomic, readonly) NSDate *refreshDate; |
|
157 |
|
9febd9
|
158 |
/** |
W |
159 |
Indicates if `currentProfile` will automatically observe `FBSDKAccessTokenDidChangeNotification` notifications |
13e53a
|
160 |
@param enable YES is observing |
9febd9
|
161 |
|
W |
162 |
If observing, this class will issue a graph request for public profile data when the current token's userID |
bad748
|
163 |
differs from the current profile. You can observe `FBSDKProfileDidChangeNotification` for when the profile is updated. |
W |
164 |
|
|
165 |
Note that if `[FBSDKAccessToken currentAccessToken]` is unset, the `currentProfile` instance remains. It's also possible |
|
166 |
for `currentProfile` to return nil until the data is fetched. |
|
167 |
*/ |
e81c27
|
168 |
+ (void)enableUpdatesOnAccessTokenChange:(BOOL)enable |
H |
169 |
NS_SWIFT_NAME(enableUpdatesOnAccessTokenChange(_:)); |
bad748
|
170 |
|
9febd9
|
171 |
/** |
W |
172 |
Loads the current profile and passes it to the completion block. |
13e53a
|
173 |
@param completion The block to be executed once the profile is loaded |
9febd9
|
174 |
|
W |
175 |
If the profile is already loaded, this method will call the completion block synchronously, otherwise it |
bad748
|
176 |
will begin a graph request to update `currentProfile` and then call the completion block when finished. |
W |
177 |
*/ |
e81c27
|
178 |
+ (void)loadCurrentProfileWithCompletion:(nullable FBSDKProfileBlock)completion; |
bad748
|
179 |
|
9febd9
|
180 |
/** |
W |
181 |
A convenience method for returning a complete `NSURL` for retrieving the user's profile image. |
13e53a
|
182 |
@param mode The picture mode |
H |
183 |
@param size The height and width. This will be rounded to integer precision. |
bad748
|
184 |
*/ |
e81c27
|
185 |
- (nullable NSURL *)imageURLForPictureMode:(FBSDKProfilePictureMode)mode size:(CGSize)size |
H |
186 |
NS_SWIFT_NAME(imageURL(forMode:size:)); |
bad748
|
187 |
|
9febd9
|
188 |
/** |
W |
189 |
Returns YES if the profile is equivalent to the receiver. |
13e53a
|
190 |
@param profile the profile to compare to. |
bad748
|
191 |
*/ |
W |
192 |
- (BOOL)isEqualToProfile:(FBSDKProfile *)profile; |
|
193 |
@end |
e81c27
|
194 |
|
H |
195 |
NS_ASSUME_NONNULL_END |
49b883
|
196 |
|
L |
197 |
#endif |