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