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