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