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