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 <Foundation/Foundation.h> |
|
20 |
|
|
21 |
#import <FBSDKCoreKit/FBSDKMacros.h> |
|
22 |
|
|
23 |
@class FBSDKGraphRequest; |
|
24 |
@class FBSDKGraphRequestConnection; |
|
25 |
|
|
26 |
/*! |
|
27 |
@typedef FBSDKGraphRequestHandler |
|
28 |
|
|
29 |
@abstract |
|
30 |
A block that is passed to addRequest to register for a callback with the results of that |
|
31 |
request once the connection completes. |
|
32 |
|
|
33 |
@discussion |
|
34 |
Pass a block of this type when calling addRequest. This will be called once |
|
35 |
the request completes. The call occurs on the UI thread. |
|
36 |
|
|
37 |
@param connection The `FBSDKGraphRequestConnection` that sent the request. |
|
38 |
|
|
39 |
@param result The result of the request. This is a translation of |
|
40 |
JSON data to `NSDictionary` and `NSArray` objects. This |
|
41 |
is nil if there was an error. |
|
42 |
|
|
43 |
@param error The `NSError` representing any error that occurred. |
|
44 |
|
|
45 |
*/ |
|
46 |
typedef void (^FBSDKGraphRequestHandler)(FBSDKGraphRequestConnection *connection, |
|
47 |
id result, |
|
48 |
NSError *error); |
|
49 |
|
|
50 |
/*! |
|
51 |
@protocol |
|
52 |
|
|
53 |
@abstract |
|
54 |
The `FBSDKGraphRequestConnectionDelegate` protocol defines the methods used to receive network |
|
55 |
activity progress information from a <FBSDKGraphRequestConnection>. |
|
56 |
*/ |
|
57 |
@protocol FBSDKGraphRequestConnectionDelegate <NSObject> |
|
58 |
|
|
59 |
@optional |
|
60 |
|
|
61 |
/*! |
|
62 |
@method |
|
63 |
|
|
64 |
@abstract |
|
65 |
Tells the delegate the request connection will begin loading |
|
66 |
|
|
67 |
@discussion |
|
68 |
If the <FBSDKGraphRequestConnection> is created using one of the convenience factory methods prefixed with |
|
69 |
start, the object returned from the convenience method has already begun loading and this method |
|
70 |
will not be called when the delegate is set. |
|
71 |
|
|
72 |
@param connection The request connection that is starting a network request |
|
73 |
*/ |
|
74 |
- (void)requestConnectionWillBeginLoading:(FBSDKGraphRequestConnection *)connection; |
|
75 |
|
|
76 |
/*! |
|
77 |
@method |
|
78 |
|
|
79 |
@abstract |
|
80 |
Tells the delegate the request connection finished loading |
|
81 |
|
|
82 |
@discussion |
|
83 |
If the request connection completes without a network error occuring then this method is called. |
|
84 |
Invocation of this method does not indicate success of every <FBSDKGraphRequest> made, only that the |
|
85 |
request connection has no further activity. Use the error argument passed to the FBSDKGraphRequestHandler |
|
86 |
block to determine success or failure of each <FBSDKGraphRequest>. |
|
87 |
|
|
88 |
This method is invoked after the completion handler for each <FBSDKGraphRequest>. |
|
89 |
|
|
90 |
@param connection The request connection that successfully completed a network request |
|
91 |
*/ |
|
92 |
- (void)requestConnectionDidFinishLoading:(FBSDKGraphRequestConnection *)connection; |
|
93 |
|
|
94 |
/*! |
|
95 |
@method |
|
96 |
|
|
97 |
@abstract |
|
98 |
Tells the delegate the request connection failed with an error |
|
99 |
|
|
100 |
@discussion |
|
101 |
If the request connection fails with a network error then this method is called. The `error` |
|
102 |
argument specifies why the network connection failed. The `NSError` object passed to the |
|
103 |
FBSDKGraphRequestHandler block may contain additional information. |
|
104 |
|
|
105 |
@param connection The request connection that successfully completed a network request |
|
106 |
@param error The `NSError` representing the network error that occurred, if any. May be nil |
|
107 |
in some circumstances. Consult the `NSError` for the <FBSDKGraphRequest> for reliable |
|
108 |
failure information. |
|
109 |
*/ |
|
110 |
- (void)requestConnection:(FBSDKGraphRequestConnection *)connection |
|
111 |
didFailWithError:(NSError *)error; |
|
112 |
|
|
113 |
/*! |
|
114 |
@method |
|
115 |
|
|
116 |
@abstract |
|
117 |
Tells the delegate how much data has been sent and is planned to send to the remote host |
|
118 |
|
|
119 |
@discussion |
|
120 |
The byte count arguments refer to the aggregated <FBSDKGraphRequest> objects, not a particular <FBSDKGraphRequest>. |
|
121 |
|
|
122 |
Like `NSURLConnection`, the values may change in unexpected ways if data needs to be resent. |
|
123 |
|
|
124 |
@param connection The request connection transmitting data to a remote host |
|
125 |
@param bytesWritten The number of bytes sent in the last transmission |
|
126 |
@param totalBytesWritten The total number of bytes sent to the remote host |
|
127 |
@param totalBytesExpectedToWrite The total number of bytes expected to send to the remote host |
|
128 |
*/ |
|
129 |
- (void)requestConnection:(FBSDKGraphRequestConnection *)connection |
|
130 |
didSendBodyData:(NSInteger)bytesWritten |
|
131 |
totalBytesWritten:(NSInteger)totalBytesWritten |
|
132 |
totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite; |
|
133 |
|
|
134 |
@end |
|
135 |
|
|
136 |
/*! |
|
137 |
@class FBSDKGraphRequestConnection |
|
138 |
|
|
139 |
@abstract |
|
140 |
The `FBSDKGraphRequestConnection` represents a single connection to Facebook to service a request. |
|
141 |
|
|
142 |
@discussion |
|
143 |
The request settings are encapsulated in a reusable <FBSDKGraphRequest> object. The |
|
144 |
`FBSDKGraphRequestConnection` object encapsulates the concerns of a single communication |
|
145 |
e.g. starting a connection, canceling a connection, or batching requests. |
|
146 |
|
|
147 |
*/ |
|
148 |
@interface FBSDKGraphRequestConnection : NSObject |
|
149 |
|
|
150 |
/*! |
|
151 |
@abstract |
|
152 |
The delegate object that receives updates. |
|
153 |
*/ |
|
154 |
@property (nonatomic, assign) id<FBSDKGraphRequestConnectionDelegate> delegate; |
|
155 |
|
|
156 |
/*! |
|
157 |
@abstract Gets or sets the timeout interval to wait for a response before giving up. |
|
158 |
*/ |
|
159 |
@property (nonatomic) NSTimeInterval timeout; |
|
160 |
|
|
161 |
/*! |
|
162 |
@abstract |
|
163 |
The raw response that was returned from the server. (readonly) |
|
164 |
|
|
165 |
@discussion |
|
166 |
This property can be used to inspect HTTP headers that were returned from |
|
167 |
the server. |
|
168 |
|
|
169 |
The property is nil until the request completes. If there was a response |
|
170 |
then this property will be non-nil during the FBSDKGraphRequestHandler callback. |
|
171 |
*/ |
|
172 |
@property (nonatomic, retain, readonly) NSHTTPURLResponse *URLResponse; |
|
173 |
|
|
174 |
/*! |
|
175 |
@methodgroup Class methods |
|
176 |
*/ |
|
177 |
|
|
178 |
/*! |
|
179 |
@method |
|
180 |
|
|
181 |
@abstract |
|
182 |
This method sets the default timeout on all FBSDKGraphRequestConnection instances. Defaults to 60 seconds. |
|
183 |
|
|
184 |
@param defaultConnectionTimeout The timeout interval. |
|
185 |
*/ |
|
186 |
+ (void)setDefaultConnectionTimeout:(NSTimeInterval)defaultConnectionTimeout; |
|
187 |
|
|
188 |
/*! |
|
189 |
@methodgroup Adding requests |
|
190 |
*/ |
|
191 |
|
|
192 |
/*! |
|
193 |
@method |
|
194 |
|
|
195 |
@abstract |
|
196 |
This method adds an <FBSDKGraphRequest> object to this connection. |
|
197 |
|
|
198 |
@param request A request to be included in the round-trip when start is called. |
|
199 |
@param handler A handler to call back when the round-trip completes or times out. |
|
200 |
|
|
201 |
@discussion |
|
202 |
The completion handler is retained until the block is called upon the |
|
203 |
completion or cancellation of the connection. |
|
204 |
*/ |
|
205 |
- (void)addRequest:(FBSDKGraphRequest *)request |
|
206 |
completionHandler:(FBSDKGraphRequestHandler)handler; |
|
207 |
|
|
208 |
/*! |
|
209 |
@method |
|
210 |
|
|
211 |
@abstract |
|
212 |
This method adds an <FBSDKGraphRequest> object to this connection. |
|
213 |
|
|
214 |
@param request A request to be included in the round-trip when start is called. |
|
215 |
|
|
216 |
@param handler A handler to call back when the round-trip completes or times out. |
|
217 |
The handler will be invoked on the main thread. |
|
218 |
|
|
219 |
@param name An optional name for this request. This can be used to feed |
|
220 |
the results of one request to the input of another <FBSDKGraphRequest> in the same |
|
221 |
`FBSDKGraphRequestConnection` as described in |
|
222 |
[Graph API Batch Requests]( https://developers.facebook.com/docs/reference/api/batch/ ). |
|
223 |
|
|
224 |
@discussion |
|
225 |
The completion handler is retained until the block is called upon the |
|
226 |
completion or cancellation of the connection. This request can be named |
|
227 |
to allow for using the request's response in a subsequent request. |
|
228 |
*/ |
|
229 |
- (void)addRequest:(FBSDKGraphRequest *)request |
|
230 |
completionHandler:(FBSDKGraphRequestHandler)handler |
|
231 |
batchEntryName:(NSString *)name; |
|
232 |
|
|
233 |
/*! |
|
234 |
@method |
|
235 |
|
|
236 |
@abstract |
|
237 |
This method adds an <FBSDKGraphRequest> object to this connection. |
|
238 |
|
|
239 |
@param request A request to be included in the round-trip when start is called. |
|
240 |
|
|
241 |
@param handler A handler to call back when the round-trip completes or times out. |
|
242 |
|
|
243 |
@param batchParameters The optional dictionary of parameters to include for this request |
|
244 |
as described in [Graph API Batch Requests]( https://developers.facebook.com/docs/reference/api/batch/ ). |
|
245 |
Examples include "depends_on", "name", or "omit_response_on_success". |
|
246 |
|
|
247 |
@discussion |
|
248 |
The completion handler is retained until the block is called upon the |
|
249 |
completion or cancellation of the connection. This request can be named |
|
250 |
to allow for using the request's response in a subsequent request. |
|
251 |
*/ |
|
252 |
- (void)addRequest:(FBSDKGraphRequest *)request |
|
253 |
completionHandler:(FBSDKGraphRequestHandler)handler |
|
254 |
batchParameters:(NSDictionary *)batchParameters; |
|
255 |
|
|
256 |
/*! |
|
257 |
@methodgroup Instance methods |
|
258 |
*/ |
|
259 |
|
|
260 |
/*! |
|
261 |
@method |
|
262 |
|
|
263 |
@abstract |
|
264 |
Signals that a connection should be logically terminated as the |
|
265 |
application is no longer interested in a response. |
|
266 |
|
|
267 |
@discussion |
|
268 |
Synchronously calls any handlers indicating the request was cancelled. Cancel |
|
269 |
does not guarantee that the request-related processing will cease. It |
|
270 |
does promise that all handlers will complete before the cancel returns. A call to |
|
271 |
cancel prior to a start implies a cancellation of all requests associated |
|
272 |
with the connection. |
|
273 |
*/ |
|
274 |
- (void)cancel; |
|
275 |
|
|
276 |
/*! |
|
277 |
@method |
|
278 |
|
|
279 |
@abstract |
|
280 |
This method starts a connection with the server and is capable of handling all of the |
|
281 |
requests that were added to the connection. |
|
282 |
|
|
283 |
@discussion By default, a connection is scheduled on the current thread in the default mode when it is created. |
|
284 |
See `setDelegateQueue:` for other options. |
|
285 |
|
|
286 |
This method cannot be called twice for an `FBSDKGraphRequestConnection` instance. |
|
287 |
*/ |
|
288 |
- (void)start; |
|
289 |
|
|
290 |
/*! |
|
291 |
@abstract Determines the operation queue that is used to call methods on the connection's delegate. |
|
292 |
@param queue The operation queue to use when calling delegate methods. |
|
293 |
@discussion By default, a connection is scheduled on the current thread in the default mode when it is created. |
|
294 |
You cannot reschedule a connection after it has started. |
|
295 |
|
|
296 |
This is very similar to `[NSURLConnection setDelegateQueue:]`. |
|
297 |
*/ |
|
298 |
- (void)setDelegateQueue:(NSOperationQueue *)queue; |
|
299 |
|
|
300 |
/*! |
|
301 |
@method |
|
302 |
|
|
303 |
@abstract |
|
304 |
Overrides the default version for a batch request |
|
305 |
|
|
306 |
@discussion |
|
307 |
The SDK automatically prepends a version part, such as "v2.0" to API paths in order to simplify API versioning |
|
308 |
for applications. If you want to override the version part while using batch requests on the connection, call |
|
309 |
this method to set the version for the batch request. |
|
310 |
|
|
311 |
@param version This is a string in the form @"v2.0" which will be used for the version part of an API path |
|
312 |
*/ |
|
313 |
- (void)overrideVersionPartWith:(NSString *)version; |
|
314 |
|
|
315 |
@end |
|
316 |
|
|
317 |
/*! |
|
318 |
@abstract The key in the result dictionary for requests to old versions of the Graph API |
|
319 |
whose response is not a JSON object. |
|
320 |
|
|
321 |
@discussion When a request returns a non-JSON response (such as a "true" literal), that response |
|
322 |
will be wrapped into a dictionary using this const as the key. This only applies for very few Graph API |
|
323 |
prior to v2.1. |
|
324 |
*/ |
|
325 |
FBSDK_EXTERN NSString *const FBSDKNonJSONResponseProperty; |