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