forked from philippec/MKAbeFook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MKFacebook.h
326 lines (193 loc) · 9.51 KB
/
MKFacebook.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
//
// MKFacebook.h
// MKAbeFook
//
// Created by Mike on 10/11/06.
/*
Copyright (c) 2009, Mike Kinney
All rights reserved.
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of MKAbeFook nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import <Cocoa/Cocoa.h>
@class MKLoginWindow;
extern NSString *MKAPIServerURL;
extern NSString *MKVideoAPIServerURL;
extern NSString *MKLoginUrl;
extern NSString *MKExtendPermissionsURL;
extern NSString *MKFacebookAPIVersion;
extern NSString *MKFacebookDefaultResponseFormat;
/*!
@class MKFacebook
MKFacebook is the starting point for logging in and communicating with Facebook. It handles displaying a login window for the user and notifying your application when a login has been successful.
To provide a user with a login window for your application you must do the following:
1. initialize a new MKFacebook object with your API key and a delegate object
2. call login or loginWithPermissions:forSheet:
3. receive confirmation of a successful login via the userLoginSuccessful delegate method
Delegate Methods
-(void)userLoginSuccessful; (required) Called when a session has been successfully retrieved from Facebook. Your MKFacebook delegate must implement this method, an exception will be raised if it doesn't.
*/
@interface MKFacebook : NSObject {
MKLoginWindow *loginWindow;
id _delegate;
BOOL _alertMessagesEnabled;
BOOL _displayLoginAlerts;
@private
BOOL useModalLogin;
}
#pragma mark Properties
#pragma mark -
#pragma mark Instantiate
/*! @name Creating and Initializing
* Create a new MKFacebook object.
*/
//@{
/*!
@brief Setup new MKFacebook object.
@param anAPIKey Your API key issued by Facebook.
@param aDelegate A delegate object that will receive calls from the MKFacebook object.
The delegate object must implement a userLoginSuccessful method that will called after a user has successfully logged in.
@result Returns allocated and initiated MKFacebook object ready to be used to log into the Facebook API.
@version 0.7 and later
*/
+ (MKFacebook *)facebookWithAPIKey:(NSString *)anAPIKey delegate:(id)aDelegate;
/*!
@brief Setup new MKFacebook object.
@param anAPIKey Your API key issued by Facebook.
@param aDelegate A delegate object that will receive calls from the MKFacebook object.
The delegate object must implement a userLoginSuccessful method that will called after a user has successfully logged in.
@result Returns initiated MKFacebook object ready to be used to log into the Facebook API.
@version 0.7 and later
*/
- (MKFacebook *)initUsingAPIKey:(NSString *)anAPIKey delegate:(id)aDelegate;
//@} //ENDS Instantiate group
#pragma mark -
#pragma mark Login and Logout
/*! @name Login and Logout
* Display login window, get information about user login status.
*/
//@{
/*!
@brief Load existing session if available or display a login window.
Tries to load existing session. If no session is available a login window will be displayed. If a user logs in successfully the session will automatically be saved to the application NSUserDefaults. If you need to display a login window while a modal window active use loginUsingModalWindow.
You can customize the message displayed in the login window after a successful or failed login attempt by creating "FacebookLoginSuccess.html" and "FacebookLoginFailed.html" files and placing them in the Resources folder of your application.
@see loginUsingModalWindow
@see loginWithPermissions:forSheet:
@version 0.9 and later
*/
- (void)login;
/*!
@brief Loads an existing session if available or displays a modal login window.
Tries to load an existing session. If no session is available a modal login window will be displayed. Use this method if you need to display a modal login window while another modal window is already visible.
If a user logs in successfully the session will automatically be saaved to the application NSUSerDefaults.
@see login
@see loginWithPermissions:forSheet:
@version 0.9 and later
*/
- (void)loginUsingModalWindow;
/*!
@brief Attempts to log a user in using existing session. If no session is available a login window is diplayed.
Tries to load existing session. If no session is available a login window will be displayed. If a user logs in successfully the session will automatically be saved to the application NSUserDefaults. See http://wiki.developers.facebook.com/index.php/Extended_permissions for a list of available permissions.
@param permissions List of permisisons to offer the user.
@param sheet If YES is passed in a NSWindow will be returned, otherwise a login window will appear and nil will be returned.
@return Either a NSWindow to be attached as a sheet or nil.
@verbatim
NSWindow *loginWindow = [fbConnection loginWithPermissions:[NSArray arrayWithObjects:@"offline_access",@"photo_upload",nil] forSheet:YES];
@endverbatim
@warning If additional permissions are requested the user must allow them or the login may not be successful.
@see login
@see loginUsingModalWindow
@version 0.9 and later
*/
- (NSWindow *)loginWithPermissions:(NSArray *)permissions forSheet:(BOOL)sheet;
/*!
@brief Checks for a valid session in NSUserDefaults.
@result Returns TRUE if valid session exists.
@see uid
*/
- (BOOL)userLoggedIn;
/*!
@brief Get the UID of the logged in user.
@result Returns uid as NSString of user currently logged in, returns nil if no user is logged in.
@see userLoggedIn
*/
- (NSString *)uid;
/*!
@brief Destoys login session.
Removes any saved sessions and invalidates any future requests until a user logs in again.
@version 0.9.0
*/
- (void)logout;
//called from MKLoginWindow after a successful login
- (void)userLoginSuccessful;
//@} //ENDS Manage User Login group
#pragma mark -
#pragma mark Extend Permisisons
/*! @name Extend Permissions
* Display a window to allow user to extent application permissions.
*/
//@{
/*!
@brief Display a window and a Facebook page to extend permisisons.
@param aString Name of extended permission to grant. See Facebook documentation for allowed extended permissions.
This method will display a new window and load the Facebook URL http://www.facebook.com/connect/prompt_permissions.php to extend permissions of the application.
@see grantExtendedPermission:forSheet:
@version 0.7.4 and later
*/
- (void)grantExtendedPermission:(NSString *)aString;
/*!
@brief Display a window and a Facebook page to extend permisisons.
@param aString Name of extended permission to grant. See Facebook documentation for allowed extended permissions.
@param forSheet BOOL to request a NSWindow that can be attached as a sheet, pass in NO to simply display the window.
This method will display a new window and load the Facebook URL http://www.facebook.com/connect/prompt_permissions.php to extend permissions of the application.
@see grantExtendedPermission:
@result Returns NSWindow or displays window.
@version 0.8.2 and later
*/
- (NSWindow *)grantExtendedPermission:(NSString *)aString forSheet:(BOOL)forSheet;
//@} //ENDS Extend Permissions group
#pragma mark -
#pragma mark Handle Login Alerts
/*! @name Handle Login Alerts
*
*/
//@{
/*!
@brief Display alert window with details of error encountered.
Set whether or not alert windows should be displayed if Facebook returns an error during the login process. Default is YES.
@param aBool Should we display the error or should we not?
@see displayLoginAlerts
@version 0.8 and later
*/
- (void)setDisplayLoginAlerts:(BOOL)aBool;
/*!
@brief Returns YES if login alerts are enabled, NO if they are not.
@result Returns YES if login alerts are enabled, NO if they are not.
@see setDisplayLoginAlerts:
@version 0.8 and later
*/
- (BOOL)displayLoginAlerts;
//@} //ENDS Handle Login Alerts group
#pragma mark -
@end
/*!
Your MKFacebook delegate must implement the userLoginSuccessful method to receive a message when a user has successfully logged in.
@version 0.8 and later
*/
@protocol MKFacebookDelegate
/*! @name Receive Login Notification
*
*/
//@{
/*!
Called when a session has been successfully retrieved from Facebook. You may now start sending requests using MKFacebookRequest.
@see MKFacebookRequest
@version 0.8 and later
*/
@required
-(void)userLoginSuccessful;
//@}
@end