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